To install Python with winget, you can use the following command:
winget install -e --id Python.Python.3.11 --scope machine
This command says "Install the app with the exact id
Python.Python.3.11
for all users on the machine."
To check that the installation was successful, enter
python
into a new command prompt. This
should start the Python interpreter.
The command above installs Python 3.11. To see which other versions are available, you can use:
winget search --id Python.Python
This gives:
Name Id Version Source ------------------------------------------------ Python 2 Python.Python.2 2.7.18150 winget Python 3 Python.Python.3.0 3.0.1 winget Python 3 Python.Python.3.1 3.1.4 winget Python 3 Python.Python.3.2 3.2.5 winget Python 3 Python.Python.3.3 3.3.5 winget Python 3 Python.Python.3.4 3.4.4 winget Python 3 Python.Python.3.5 3.5.4 winget Python 3 Python.Python.3.6 3.6.8 winget Python 3 Python.Python.3.7 3.7.9 winget Python 3 Python.Python.3.8 3.8.10 winget Python 3 Python.Python.3.9 3.9.13 winget Python 3.10 Python.Python.3.10 3.10.11 winget Python 3.11 Python.Python.3.11 3.11.4 winget Python 3.12 Python.Python.3.12 3.12.0b4 winget
The suffix 0b4
in version 3.12
indicates
a beta version.
As another example from the table, we can install Python 3.9 with the command:
winget install -e --id Python.Python.3.9 --scope machine
Because we passed the flag --scope machine
above,
Python was installed for all users. In our specific examples, its
installation directories are
C:\Program Files\Python311
and
C:\Program Files\Python39
, respectively. If we had
not passed the flag, then Python would have been installed for the
current user only. In this case, the installation directories
would have been
C:\Users\<YourUser>\AppData\Local\Programs\Python\Python311
,
etc.
It is possible to customize the install location with the
--location
flag:
winget install -e --id Python.Python.3.11 --location C:\Python311
This installs Python into C:\Python311
.
We can see from the above table that it's also possible to install Python 2 with winget:
winget install -e --id Python.Python.2
It doesn't matter whether we pass --scope machine
here because this always performs a system-wide installation.
The installation directory is C:\Python27
.
The Python 3 installers add Python to the PATH environment
variable. This lets us write python
in a (new)
command prompt window to launch the interpreter. Python 2 does not
add itself to the PATH.
When you try to install multiple Python versions with winget, you
will get a message Found an existing package already
installed. Trying to upgrade the installed package...
This means that you cannot use winget to manage multiple parallel
Python installations. There are other tools that let you achieve
this, such as
pyenv-win.