How can I ensure that when I enter python3 in a CLI prompt that it launches my preferred version of python (3.13)?
By altering the environment variable named
PATHso that it includes
C:\Users\user\AppData\Local\Python\pythoncore-3.13-64
earlier in the path than the location of any other versions of python. Ideally it would be the only occurrence in PATH of a location of a Python version. The others should be omitted. Or ...By removing any Python locations from
PATHand creating apython3.cmdfile in a location inPATH. For example, I have ascriptsfolder in my home directory that I include in myPATH. Thepython3.cmdcan temporarily adjust PATH if python needs it to e.g find libraries etc.
How to set default version when multiple versions are installed
Allow setting a python version using py use 3.13 command
How can I set the default Python version that gets launched when typing python3 (On Windows 11)?
How to change default python in `py-launcher` at windows?
I have both 3.10 and 3.11b3 installed on my windows 10 machine. I'd like py.exe to launch 3.10.
I had read that I should create py.ini and pyw.ini in both \windows and C:\Users<user>\AppData\Local\Programs\Python\Launcher\ and the files should contain:
[defaults] python=3.10
I've done this, but py.exe launches 3.11b3. I don't have any other py.ini files. How do I fix this so \windows\py.exe launches my preferred default version?
EDIT: see https://stackoverflow.com/questions/68121982/multiple-python-versions-installed-how-to-set-the-default-version-for-py-exe
I could use py -3.10 to launch, but from the link there should be a way to just use py
If anyone is looking for this in 2023:
Goto your Environment Variables....
Under System variables, look for the variable PY_PYTHON. If it exists, you can change its value to the version of Python you want to use by default (for example, 3.10 or 3.11). If it doesn't exist, you can create it by clicking on New..., entering PY_PYTHON as the variable name, and the desired Python version as the variable value.
Click OK to apply the changes.
To verify your changes, open a new command prompt and type py. It should start the Python interpreter in the version you specified.
To set the default version of Python, you need to have installed Python Launcher (cf below for some info). If you didn't, you can probably install it by using the installation .exe of one of your Python installations, and selecting modifying/repair.
You also need to know where your Python Launcher is:
- if you installed it for all users, it is in
C:\WINDOWS\, - if not, it is in
%USERPROFILE%\AppData\Local\Programs\Python\Launcher\.
In this example, the latest installed version of Python is Python 3.11 but the version that should be the default one is Python 3.6.
To set a default Python version:
go to your Python Launcher Folder and create 2 files:
py.iniandpyw.inimake sure that both of these files are UFT-8 (they shouldn't be UFT-8 with BOM)
add to each of these files:
[defaults] python=3.6now, right click on any
.py, selectopen with, selectcheck another app, checkAlways use this app..., scroll all the way down and click onmore app...and navigate to your Python Launcher folder and select thepy.exe.do the previous step again but this time, right-click on a
.pywfile and select thepyw.exe.
How to use it
● in a CMD:
Do not use anymore
pythoninCMD, always usepy. If you type justpy, then it will open a Python 3.6 console. If you want a Python 3.11 console, typepy -3.11.As indicated in the comment by @karl-knechtel: If you have an active
venv, using python instead ofpy` will prioritize the venv's Python, which is generally what you want.To use pip to install :
py -3.11 -m pip install # will install package for 3.11 py -m pip install # will install package for 3.6
● For python files:
- If the file doesn't contain a shebang, then it will be started with the default Python version which is
3.6. - To use
Python 3.11for this file, add the shebang#!python3.11at the very top of your script
To verify that everything is working:
open a
CMD, writepy -0pand look for the*. It should be next to the default version you have set in the.inifiles.Installed Pythons found by py Launcher for Windows
-3.11-64 C:\Users<user>\AppData\Local\Programs\Python\Python39\python.exe
-3.6-64 C:\Users<user>\AppData\Local\Programs\Python\Python36\python.exe *With this setup, you can use the specific version of Python that you need in your scripts:
3.6 (as it will call the default version)
import sys print(sys.version_info) input("close")3.6 (as it will call the default)
#!python import sys print(sys.version_info) input("close")3.11
#!python3.11 import sys print(sys.version_info) input("close")3.11 (as it is the latest python 3 installed)
#!python3 import sys print(sys.version_info) input("close")
Some info about the Python launcher from docs.python.org
The Python launcher for Windows is a utility which aids in locating and executing of different Python versions. It allows scripts (or the command-line) to indicate a preference for a specific Python version, and will locate and execute that version. Unlike the PATH variable, the launcher will correctly select the most appropriate version of Python. It will prefer per-user installations over system-wide ones, and orders by language version rather than using the most recently installed version.
Two .ini files will be searched by the launcher - py.ini in the current user’s “application data” directory [...] and py.ini in the same directory as the launcher. The same .ini files are used for both the ‘console’ version of the launcher (i.e. py.exe) and for the ‘windows’ version (i.e. pyw.exe).
Customization specified in the “application directory” will have precedence over the one next to the executable, so a user, who may not have write access to the .ini file next to the launcher, can override commands in that global .ini file.
⚠ Your python version can be installed either for all user (python.exe will be in program files) or for the profile (python.exe will be in appdata). If it doesn't work, try uninstalling all python version, and the launcher and reinstall everything as current user to start clean. To do that, download the .exe of your current Python installation, run it and click on uninstall (dont delete the remaining folder in app data if you want to keep your python packages), then reinstall it. If you install the launcher for all users but python for current user, your python.exe will be in appdata (a folder for each version), and your launcher will be C:\Windows\py.exe
If you want to install it for all "all users" and the check box is grayed out: you need first to uninstall the python launcher. If it's still grayed uninstall the python version(s) that remains (everything wil be in program files).
python/pymanager: The Python Install Manager (for Windows)
it seems python released it's own version manager (like pyenv, uv) , which can help manager mutiple python versions and set default , auto download ...
it't very new , i just found out yesterday , i didn't see people talk about it
any way , it's new and provide more options , we can try it .