I noticed a change with py.exe for Windows in Python 3.11.
Example test script - “myscript1.py”:
#!/usr/bin/env python3
import sys
print(f'Testing running using Python {sys.version}')
Note: The shebang syntax is officially supported for Python for Windows per:
4. Using Python on Windows — Python 3.11.0 documentation
Results running test script with Python 3.10 for Windows (64-bit version):
myscript1
Testing running using Python 3.10.8...
Results using Python 3.11 for Windows (64-bit version):
myscript1
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Results using Python 3.11 using python binary:
python myscript1.py
Testing running using Python 3.11.0...
Results using Python 3.11, call py launcher directly:
py myscript1.py
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
Results using Python 3.10’s py launcher directly:
py310 myscript1.py
Testing running using Python 3.11.0...
Results using Python 3.11’s py launcher directly with any argument:
py -b myscript1.py
Testing running using Python 3.11.0...
If I edit myscript1.py and change the shebang line to this:
#!/usr/bin/env python
Then it works:
myscript1
Testing running using Python 3.11.0...
So, it appears the py.exe launcher included with Python 3.11 does not work if the shebang line is like this:
#!/usr/bin/env python3
Unless an argument is passed - then it works.
This is a change from Python 3.10 and since the behavior does not appear to be consistent it appears this could be a bug.
Before I open an issue on the GitHub CPython tracker, I wanted to check here.
Thoughts?
–Jim