shell – Should I put #! (shebang) in Python scripts, and what form should it take? – Stack Overflow
Posted by jpluimers on 2019/12/17
It is very important to get the shebang correct. In case of Python, you both need env and the correct Python main version.
Answer
Correct usage for Python 3 scripts is:
#!/usr/bin/env python3This defaults to version 3.latest. For Python 2.7.latest use
python2in place ofpython3.Comment
envwill always be found in/usr/bin/, and its job is to locate bins (like python) usingPATH. No matter how python is installed, its path will be added to this variable, andenvwill find it (if not, python is not installed). That’s the job ofenv, that’s the whole reasonwhy it exists. It’s the thing that alerts the environment (set up env variables, including the install paths, and include paths).
Source: [WayBack] shell – Should I put #! (shebang) in Python scripts, and what form should it take? – Stack Overflow
Thanks GlassGhost and especially flornquake for the answer and Elias Van Ootegem for the comment!
The answer is based on [WayBack] PEP 394 — The “python” Command on Unix-Like Systems | Python.org.
The env is always in the same place, see env – Wikipedia and Shebang (Unix) – Wikipedia.
–jeroen






Leave a comment