Skip to content

python3.exe ignores PYTHON_MANAGER_DEFAULT when the script has shebang #249

@DarkDaskin

Description

@DarkDaskin

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:

  1. Launch cmd.exe
  2. Invoke py and let it install the default Python version (which is 3.14 currently)
  3. Invoke py install 3.8
  4. Invoke python3 --version and see that it selects Python 3.14
  5. Switch to Python 3.8 with set PYTHON_MANAGER_DEFAULT=3.8
  6. Invoke python3 --version and see that it selects Python 3.8
  7. Prepare a script test.py with the following content:
#!/usr/bin/env python3
import sys
print(sys.version)
  1. Invoke python3 test.py and 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions