Python is installed to all of our computers because it is useful framework for a variety of things .
To use the python interface from terminal just type python .
to check you python version just type python --version
to run a python script you need to type in the form :
./python_script_name.py
but very importantly it has to be executable first
chmod +x python_script_name.py
I hope it helps !
Answer from billybadass on askubuntu.comPython is installed to all of our computers because it is useful framework for a variety of things .
To use the python interface from terminal just type python .
to check you python version just type python --version
to run a python script you need to type in the form :
./python_script_name.py
but very importantly it has to be executable first
chmod +x python_script_name.py
I hope it helps !
just type :
sudo apt-get install python
It will show you whether you have newest version of python or you should upgrade
https://docs.python.org/3.6/using/windows.html#installing-without-ui
Installing Without UI: All of the options available in the installer UI can also be specified from the command line, allowing scripted installers to replicate an installation on many machines without user interaction. These options may also be set without suppressing the UI in order to change some of the defaults.
To completely hide the installer UI and install Python silently, pass the /quiet option. To skip past the user interaction but still display progress and errors, pass the /passive option. The /uninstall option may be passed to immediately begin removing Python - no prompt will be displayed.
All other options are passed as name=value, where the value is usually 0 to disable a feature, 1 to enable a feature, or a path.
I have used windows PowerShell to achieve this:
Download Python Exe File.. Feel free to edit 'URI' for the updated version of Python &
outFilefor your preferred Windows locationInvoke-WebRequest -UseBasicParsing -Uri \ 'https://www.python.org/ftp/python/3.11.0/python-3.11.0-amd64.exe' \ -OutFile 'c:/veera/python-3.11.0-amd64.exe'Install Python via Command Prompt
.\python-3.11.0-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0Set Python location
setx /M path "%path%;C:\Program Files\Python311\" $env:PATH =$env:PATH+";C:\Program Files\Python311\"
You're good to use Python from command prompt now :)
Installing python on Linux - help?
Python 3 installation on windows running from command line - Stack Overflow
How SHOULD you install Python on Mac OS?
New pc: how do I install python *correctly* this time?
Videos
The best way to install Python through Windows Command Prompt will be through Chocolatey (Windows Package Manageer).
Steps to install python 3 will be as follows :-
Open CMD using 'Run as Administrator'.
Download and Install Chocolatey using the following command.
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
- Download and install python using the following command.
choco install -y python3
- You can check the version to verify if Python was successfully installed as follows.
python --version
You could download the setup you want to install and then install it automatically without using the setup's UI:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe" -OutFile "c:/temp/python-3.7.0.exe"
c:/temp/python-3.7.0.exe /quiet InstallAllUsers=0 InstallLauncherAllUsers=0 PrependPath=1 Include_test=0
I don't think it will work without admin privileges though, I tried using InstallAllUsers=0 to install it only for the current user but it is still asking for elevation.
There are some options you can use when installing it this way, here is the doc: https://docs.python.org/3.6/using/windows.html#installing-without-ui
I am a long-time user of Python but I have never understood how to install python "properly" - I tend to figure out some way to get it done when I need to, and then forget all about it. But I want to understand it a bit better because it isn't straightforward in my opinion. I am not considering Pyenv or other such "helper" tools/dependencies - I want to learn how to do this the "official" way. I've looked at the official docs but can't see what I've done incorrectly. The main issue is that at some stage I often find myself wanting a newer version of python than what is provided, and then I end up a bit stuck.
I installed Debian and it came with python3 under my /usr/local/bin directory. There is also a Python installation under /usr/bin/python3.11, which I guess is my system python? I believe I was always interacting with my /usr/local/bin python - not the system python, so that's good. (Also I'm always using virtual environments, so let's not discuss their importance please). That was working fine for me, but now I want to upgrade my version of python and I am facing difficulties.
-
What should I do to upgrade python in an "official" way (i.e. not adding dev repositories like deadsnakes, not using helper tools like Pyenv)?
-
What do I need to do with pip? Currently, the pip command actually points to
/usr/bin/python- i have to use pip3* (see below). -
Can I simply delete the old python and pip versions from
/usr/local/binif I wanted to? -
How do I ensure that every time I type
python3in the terminal, it grabs the latest one? Do I just ensure it is higher up in my PATH variable? -
Why is there not one simple way to do this? Obviously everyone has slightly different needs, but I imagine 80% of python users just want to use python and have a reasonable way to upgrade when required without screwing something up in their system.
To explain why I'm asking this now, I installed the python source from the main website yesterday and tried to get it working but something is off. Here's what I did
-
Extracted the Python-3.12.3.tar.xz
-
Moved into the dir and ran
./configure --enable-optimizations --with-ensurepip=install -
Ran
make -
Ran
sudo make install
This worked, but I notice when I run python in the terminal REPL that I can't use the up/down keys to cycle through my command history:
>>> print("hello")
hello
>>> ^[[A*Also, I notice that I now have pip (/usr/bin/python), pip3, and pip3.12 now, and I am confused about that. Should I alias pip with pip3.12 to prevent interacting with the system python? Should I just delete pip3 and make sure pip3 points to pip3.12?
These issues have convinced me that I've now installed python incorrectly somehow. I found some info about readline but that's deprecated, and I am starting to go down the rabbit hole of running random commands to try and fix things, which is probably going to make things worse.
the reason I am asking is because I have both the Python 2 and 3 interpreter installed on my computer, and so it is ambiguous, as both are run using the command "python".
To run Python 2 executable:
C:\> py -2
To run Python 3 executable:
C:\> py -3
where py is a Python launcher that is bundled with your Python 3 installation.
py recognizes the shebang (e.g., #!/usr/bin/env python3 causes Python 3 executable to be run), it respects virtualenv (if you run py without specifying the explicit python executable version) i.e., run:
C:\> py your_script.py
and the correct python version is used automatically -- you don't need to specify the Python version on the command-line explicitly.
is there a particular reason why Python 3.x is not installed on Windows to run default with the command line "python3", like it does on Mac OSX and Linux?
OSX and Linux have python executable installed by default as a rule and it refers to Python 2 version in most cases at the moment that is why you need a separate python3 name there.
There is no Python on Windows by default. And therefore any version that you've installed is just python (I guess). The recommended way to manage multiple python versions is to use the Python launcher.
Is there some kind of way to configure Python so that it runs like this?
If you want to type python3 some_script.py instead of py some_script.py or even just some_script (assuming .py is in %PATHEXT% and Python launcher is configured to run Python scripts (check assoc .py and ftype Python.File) -- the default) then create a bat-file e.g., python3.cmd and put it in %PATH%:
"C:\path to\Python 3.X\python.exe" %*
You likely missed the checkbox at the bottom of the installer.
Full documentation here: https://docs.python.org/3/using/windows.html
Then, I think you just run python, not python3 from the Command Prompt. The reason Unix systems have python3 is because python defaults to Python2.x in many systems.
