|
|
Subscribe / Log in / New account

Arch Linux drops Python 2

Arch Linux drops Python 2

Posted Sep 26, 2022 12:15 UTC (Mon) by agateau (subscriber, #57569)
In reply to: Arch Linux drops Python 2 by zwol
Parent article: Arch Linux drops Python 2

I felt similarly for a while, until I found out the official Python 3 Windows installer, does not install a python3.exe binary, so any shebang explicitly referring to python3 fails on Windows.


to post comments

Shebang lines for Python on Windows

Posted Sep 26, 2022 13:20 UTC (Mon) by rschroev (subscriber, #4164) [Link] (1 responses)

Windows itself does not interpret shebang lines. These days (since Python 3.3) the Python installer installs a utility, the "Python Launcher for Windows" (py.exe), which is configured as the default file association for Python scripts. The launcher does interpret the shebang line (limited to a few common formats) and launches the appropriate python executable.

#!/usr/bin/env python launches the default Python
#!/usr/bin/env python2 launches the most recent Python 2
#!/usr/bin/env python3.9 launches Python 3.9

See https://docs.python.org/3/using/windows.html#python-launc... and more specifically https://docs.python.org/3/using/windows.html#shebang-lines

In a nutshell, this makes it possible to have shebang lines that work on both Windows and Unix-like operating systems.

Shebang lines for Python on Windows

Posted Sep 26, 2022 14:05 UTC (Mon) by agateau (subscriber, #57569) [Link]

Interesting. I never used py.exe. That can be handy, but it would not have helped in my case. We were using Python in our CI and the assumption was: since we start the script from Git Bash, the shebang is going to work properly, because Bash knows about shebangs. And indeed it does, but we still could not write "#!/usr/bin/env python3" because there was no python3.exe file (until we created one by copying python.exe to python3.exe, meh).

I still believe being able to reliably depend on the availability of a python3 binary on all supported platforms would have helped a lot.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds