Description
Describe the bug
When running a script with a shebang, only python versions installed by pymanager will be run. When the shebang specifies a python version installed with a different method, py.exe incorrectly uses the default interpreter version instead. The intended version is available from an existing installation and is shown in pymanage list
To Reproduce
On the system below Python 3.10 has been installed using pymanage, and Python3.12 is an existing installation.
PS C:\Users\clawrence\dev\pymanager> pymanager list
Tag Name Managed By Version Alias
3.10[-64] Python 3.10.11 PythonCore 3.10.11 python[w]3.10.exe, python[w]3.exe
3.14-dev[-64] * Python 3.14.0b1 PythonCore 3.14.0b1 python[w]3-64.exe, python[w]3.14-64.exe, python...
* These runtimes were found, but cannot be updated or uninstalled. *
3.13 Python 3.13 (64-bit) PythonCore 3.13.0
3.13 Python 3.13 (64-bit) PythonCore 3.13.3
3.12 Python 3.12 (64-bit) PythonCore 3.12.7
3.11 Python 3.11 (64-bit) PythonCore 3.11.9
3.10 Python 3.10 (64-bit) PythonCore 3.10.11
3.8 Python 3.8 (64-bit) PythonCore 3.8.10
Some columns were truncated. Use '--format=json' or '--format=jsonl' for full information.
Create two test scripts with a shebang that call the desired python version:
PS C:\Users\clawrence\dev\pymanager> "#! /usr/bin/env python3.12
>> import sys
>> print(sys.version)
>> print(sys.executable)" | Out-File -FilePath 3.12.py
PS C:\Users\clawrence\dev\pymanager> "#! /usr/bin/env python3.10
>> import sys
>> print(sys.version)
>> print(sys.executable)" | Out-File -FilePath 3.10.py
Calling Python 3.12 (which was not installed by pymanager) runs the default interpreter:
PS C:\Users\clawrence\dev\pymanager> py .\3.12.py
3.14.0b1 (tags/v3.14.0b1:b092705, May 7 2025, 10:22:31) [MSC v.1943 64 bit (AMD64)]
C:\Users\clawrence\AppData\Local\Python\pythoncore-3.14-64\python.exe
Calling Python 3.10 (installed by pymanager) runs correctly:
PS C:\Users\clawrence\dev\pymanager> py .\3.10.py
3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
py.exe
can run both interpreters correctly when specified as a cli arg:
C:\Users\clawrence\AppData\Local\Python\pythoncore-3.10-64\python.exe
PS C:\Users\clawrence\dev\pymanager> py -3.12 --version
Python 3.12.7
PS C:\Users\clawrence\dev\pymanager> py -3.10 --version
Python 3.10.11
Installing 3.12 using pymanager and the shebang works correctly:
PS C:\Users\clawrence\dev\pymanager> pymanager install 3.12
Installing Python 3.12.10.
Extracting: ...................................................................✅
Global shortcuts directory is not on PATH. Add it for easy access to global Python commands.
Directory to add: C:\Users\clawrence\AppData\Local\Python\bin
Python 3.12.10 will be launched by python3-64.exe, python3.12-64.exe, python3.12.exe, python3.exe, pythonw3-64.exe, pythonw3.12-64.exe, pythonw3.12.exe, pythonw3.exe
PS C:\Users\clawrence\dev\pymanager> py .\3.12.py
3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]
C:\Users\clawrence\AppData\Local\Python\pythoncore-3.12-64\python.exe
PS C:\Users\clawrence\dev\pymanager> pymanager uninstall 3.12
Uninstall Python 3.12.10? [Y/n] y
Removed Python 3.12.10
PS C:\Users\clawrence\dev\pymanager> py .\3.12.py
3.14.0b1 (tags/v3.14.0b1:b092705, May 7 2025, 10:22:31) [MSC v.1943 64 bit (AMD64)]
C:\Users\clawrence\AppData\Local\Python\pythoncore-3.14-64\python.exe
PS C:\Users\clawrence\dev\pymanager>
Expected behavior
py.exe
should use the python version specified in the shebang, or return an error it the requested version isn't found.
Additional context