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.
Activity
zooba commentedon Jan 12, 2026
It should match
py -3, which is going to be the latest 3.x version available fromPythonCore, so this behaviour is correct, if potentially unintuitive. It matches the intended behaviour for apython3symlink on POSIX (which doesn't always work like that, because there are ways to break it, but it's the intended behaviour to provide the latest Python 3.x).The alternative behaviour - work like
py- raises the question of what to do if the default tag is not a 3.x version? Shouldpython3launch Python 2.x if that's what is specified? Or should it choose arbitrarily? Or should it fail?DarkDaskin commentedon Jan 13, 2026
Just checked how it works with Python 2.x:
So it seems that
python3.exeworks as an alias forpython.exeand already will launch Python 2.x when that is the chosen version.This issue is not about
pythonvspython3command, it is about executing scripts with and without shebang. It is counterintuitive that presence of shebang alters already present version choice logic.zooba commentedon Jan 13, 2026
Oh okay then, my mistake.
It's also counterintuitive that it would launch the default when there's information available telling it which one it should use.
The shebangs are actually pretty confusing in general, and I wish we didn't have to support them at all. But I guess in this case it's finding the
python3and interpreting it likepy -V:3(because that's what it'd do for e.g.python3.14-->-V:3.14) and so it overrides the default.I'd need to look back at the spec to see how we described this case. The only thing we'd change is to treat
python3commands the same aspythoncommands, assuming the specs allow it.multiplemonomials commentedon Mar 31, 2026
Just ran into this and it confused the fsck out of me. Would really appreciate if we could fix this so
PYTHON_MANAGER_DEFAULTis respected for scripts with shebangs.zooba commentedon Mar 31, 2026
@multiplemonomials Just for clarity, you had a script with a
/bin/python3-like shebang (specifically thepython3part) that you launched withpyorpythonand expected it to choosePYTHON_MANAGER_DEFAULT?If the script had a different shebang, or you used a different command to launch it, then the change I've proposed here is not likely to help you and we'll have to look at other ways to reduce the confusion.
multiplemonomials commentedon Mar 31, 2026
Yes that's exactly what happened to me. It seems incredibly unintuitive that running
python3on the command line does not use the same python version as a script that haspython3in the shebang.Allow python3 shebangs to use default runtime.
Merge branch 'main' into pythongh-249
Allow python3 shebangs to use default runtime. (#296)