-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Install source and version
- Installed from the Windows Store
- Installed with the MSIX from python.org
- Installed with the MSI from python.org
- Installed with
winget install 9NQ7512CXL7T
Version: 25.2.240.0
Describe the bug
I wanted to use the PYTHON_MANAGER_DEFAULT environment variable to select specific Python version to use in the current shell session. It works for invoking python3 directly or running scripts without shebang, but scripts with shebang always run in the latest available Python version, which may break them.
To Reproduce
Steps to reproduce the behavior:
- Launch
cmd.exe - Invoke
pyand let it install the default Python version (which is 3.14 currently) - Invoke
py install 3.8 - Invoke
python3 --versionand see that it selects Python 3.14 - Switch to Python 3.8 with
set PYTHON_MANAGER_DEFAULT=3.8 - Invoke
python3 --versionand see that it selects Python 3.8 - Prepare a script
test.pywith the following content:
#!/usr/bin/env python3
import sys
print(sys.version)
- Invoke
python3 test.pyand see that it selects Python 3.14
Expected behavior
The script runs in Python 3.8.
Additional context
PEP 773 states that it should match a global alias listed for an install. Currently it works this way, but it is counter-intuitive and makes it not possible to choose Python version when a script relies on global python3 being of specific version. The PEP also states that the specific patterns to be detected are left to the implementation, so respecting PYTHON_MANAGER_DEFAULT in case of #!/usr/bin/env python3 does not seemingly contradict the spec.