Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

Barry Scott barry at barrys-emacs.org
Sat Dec 23 06:56:00 EST 2023



> On 23 Dec 2023, at 03:01, Thomas Passin via Python-list <python-list at python.org> wrote:
> 
> Not on my system. It may depend on whether Python gets installed to Program Files or to %USERPROFILE%/AppData/Local/Programs/Python.  Python 3.9 is the last verson I installed to Program Files, and that's the version that Windows thinks it should use to run Python files.
> 
> Run the little test program I posted.  That will tell you which version of Python the system wants to use.

I always install for all users and this what I get on my Windows 10 and 11 systems.
As you can see the shebang lines do what is expected based on the config of py.exe.

Maybe it works differently if you install for a single user only,
I do not have such a setup to test with.

Windows 10 output.

K:\shebang>py -0 
 -V:3.13          Python 3.13 (64-bit)
 -V:3.13-32       Python 3.13 (32-bit)
 -V:3.12 *        Python 3.12 (64-bit)
 -V:3.12-32       Python 3.12 (32-bit)
 -V:3.11          Python 3.11 (64-bit)
 -V:3.11-32       Python 3.11 (32-bit)
 -V:3.10          Python 3.10 (64-bit)
 -V:3.10-32       Python 3.10 (32-bit)
 -V:3.9           Python 3.9 (64-bit)
 -V:3.9-32        Python 3.9 (32-bit)
 -V:3.8           Python 3.8 (64-bit)
 -V:3.8-32        Python 3.8 (32-bit)
 -V:3.7           Python 3.7 (64-bit)
 -V:3.7-32        Python 3.7 (32-bit)
 -V:3.6           Python 3.6 (64-bit)
 -V:3.6-32        Python 3.6 (32-bit)
 -V:3.5           Python 3.5
 -V:3.5-32        Python 3.5-32
 -V:3.4           Python 3.4
 -V:3.4-32        Python 3.4-32
 -V:2.7           Python 2.7
 -V:2.7-32        Python 2.7-32

K:\shebang>type shebang_py2.py 
#!/usr/bin/python2
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_py2.py 
I am python sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)

K:\shebang>shebang_py2.py
I am python sys.version_info(major=2, minor=7, micro=17, releaselevel='final', serial=0)

K:\shebang>type shebang_py3.py 
#!/usr/bin/python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_py3.py 
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>type shebang_env_py3.py 
#!/usr/bin/env python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_env_py3.py 
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=1, releaselevel='final', serial=0)

K:\shebang>type shebang_env_py3_10.py 
#!/usr/bin/env python3.10
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

K:\shebang>py shebang_env_py3_10.py 
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

K:\shebang>shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

K:\shebang>assoc .py 
.py=Python.File

K:\shebang>ftype Python.File 
Python.File="C:\WINDOWS\py.exe" "%L" %*


Windows 11 output


: 11:52:10.36 K:\shebang
: \\BARNSTONE\barry> py -0 
 -V:3.12 *        Python 3.12 (64-bit)
 -V:3.12-32       Python 3.12 (32-bit)
 -V:3.11          Python 3.11 (64-bit)
 -V:3.11-32       Python 3.11 (32-bit)
 -V:3.10          Python 3.10 (64-bit)
 -V:3.9           Python 3.9 (64-bit)
 -V:3.9-32        Python 3.9 (32-bit)
 -V:3.8           Python 3.8 (64-bit)
 -V:3.8-32        Python 3.8 (32-bit)

: 11:52:10.40 K:\shebang
: \\BARNSTONE\barry> type shebang_py2.py 
#!/usr/bin/python2
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.41 K:\shebang
: \\BARNSTONE\barry> py shebang_py2.py 
No suitable Python runtime found
Pass --list (-0) to see all detected environments on your machine
or set environment variable PYLAUNCHER_ALLOW_INSTALL to use winget
or open the Microsoft Store to the requested version.

: 11:52:10.47 K:\shebang
: \\BARNSTONE\barry> type shebang_py3.py 
#!/usr/bin/python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.49 K:\shebang
: \\BARNSTONE\barry> py shebang_py3.py 
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.52 K:\shebang
: \\BARNSTONE\barry> shebang_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.58 K:\shebang
: \\BARNSTONE\barry> type shebang_env_py3.py 
#!/usr/bin/env python3
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.60 K:\shebang
: \\BARNSTONE\barry> py shebang_env_py3.py 
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.65 K:\shebang
: \\BARNSTONE\barry> shebang_env_py3.py
I am python sys.version_info(major=3, minor=12, micro=0, releaselevel='final', serial=0)

: 11:52:10.72 K:\shebang
: \\BARNSTONE\barry> type shebang_env_py3_10.py 
#!/usr/bin/env python3.10
from __future__ import print_function
import sys
print('I am python %r' % (sys.version_info,))

: 11:52:10.72 K:\shebang
: \\BARNSTONE\barry> py shebang_env_py3_10.py 
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

: 11:52:10.77 K:\shebang
: \\BARNSTONE\barry> shebang_env_py3_10.py
I am python sys.version_info(major=3, minor=10, micro=11, releaselevel='final', serial=0)

: 11:52:10.83 K:\shebang
: \\BARNSTONE\barry> assoc .py 
.py=Python.File

: 11:52:10.83 K:\shebang
: \\BARNSTONE\barry> ftype Python.File 
Python.File="C:\WINDOWS\py.exe" "%L" %*

Barry



More information about the Python-list mailing list