

Luckily, the correct shebang is created automatically in most cases by setuptools or your distribution package tools (on Windows, setuptools can generate wrapper. It is bad if some tool breaks if you activate a virtualenv in your shell. Note: installed scripts should use a specific python executable e.g., /usr/bin/python or /home/me/.virtualenvs/project/bin/python. This form is understood even on Windows (Python launcher). If you write a shebang manually then always use #!/usr/bin/env python unless you have a specific reason not to use it.

on POSIX, it is necessary if you want to run the script directly without invoking python executable explicitlyĪre these equally portable? Which form is used most?.whether it can be run only on python2, python3 or is it Python 2/3 compatible.Put a shebang into a Python script to indicate: Should I put the shebang in my Python scripts? ― "#!/usr/bin/env python" vs "#!/usr/local/bin/python" "python may be installed at /usr/bin/python or /bin/python in those The reason for these recommendations, given in PEP 394, is that python can refer either to python2 or python3 on different systems.Īlso, do not use: #!/usr/local/bin/python
SHOULD I REMOVE IT REDDIT CODE
The following should not be used (except for the rare case that you are writing code which is compatible with both Python 2.x and 3.x): #!/usr/bin/env python However, which shebang line you use is important.Ĭorrect usage for (defaults to version 3.latest) Python 3 scripts is: #!/usr/bin/env python3Ĭorrect usage for (defaults to version 2.latest) Python 2 scripts is: #!/usr/bin/env python2 It isn't necessary but generally put there so when someone sees the file opened in an editor, they immediately know what they're looking at. The shebang line in any script determines the script's ability to be executed like a standalone executable without typing python beforehand in the terminal or when double clicking it in a file manager (when configured properly).
