Recommend #!python Shebang for Python Packages
Idea: Recommend #!python Shebang for Python Packages
Summary
Many (if not most) Python packages use #!/usr/bin/env python in their shebang to avoid specifying a hardcoded interpreter path, letting them run on different systems without modification. This approach finds the first Python interpreter in the user's $PATH, which is often a virtual environment for Python developers. While this generally works for packages on PyPI, it's a major friction point for system tools like namcap (see pacman/namcap#19 and pacman/namcap#52) and meld, which typically aren't installed in a virtual environment.
In modern Python packaging, #!/usr/bin/env python isn't necessary anymore. The #!python shebang automatically gets rewritten to point to the correct interpreter, or you can rely on console_scripts to setup the correct interpreter. For instance, reflector already uses this generic shebang. Another viable alternative is explicitly specifying #!/usr/bin/python, which is correct on Arch Linux and is used by some packages (deheader, weechat-matrix).
Specification
- Recommend the use of
#!pythonin the Python package guidelines. - Update Arch Linux tools (e.g., namcap) to use
#!python. - Encourage maintainers to patch packages (downstream or upstream) to adopt
#!python.
Drawbacks
As noted by PyPA, rewriting #!python isn't mandatory, but modern installers already do it. Since Arch uses recent setuptools, this shouldn't pose a problem.
A real corner case is when makepkg is run inside an active virtual environment: in that scenario, #!python might resolve to #!$VIRTUAL_ENV/bin/python rather than #!/usr/bin/python. That's potentially confusing, but can be mitigated by disabling the virtual environment before building or using a clean chroot.