Is "#!/usr/bin/env python" the better shebang line ?
rylesny at gmail.com
Mon Sep 7 10:05:10 CEST 2009
On Sep 6, 10:01 am, Timothy Madden <terminato... at gmail.com> wrote:
> Sorry if this has been discussed before, my search did not find it.
> My questions is if I should use
> #!/usr/bin/env python
> as the shebang line in a portable and open python script and if it does
> help with portability and usage.
Note that there is one limitation of /usr/bin/env on many systems: you
cannot supply any arguments to the interpreter.
e.g. #!/usr/bin/env python -u
The above will fail on many systems as env will literally try to find
a file named "python -u".
Another, more obvious, case where you might avoid /usr/bin/env is when
you know (or might expect in the future) that there is another Python
version on the system which your script will not work with. Then it's
often convenient to hard code the interpreter path. This comes up
mostly in environments where you're not the administrator and have
another Python version installed in a custom place which you (and any
co-developers) have in their PATH. For example, if you wanted to share
your script with a non-team member, then having /usr/bin/env in your
script would force them to have to change their PATH first.
> Then, supposing /usr/bin/env is better than /usr/bin/python and I use
> it, is it not the case that many editors and code analysing programs,
> that want to know the script language for syntax highlighting, code
> completion, tags and source code browsing, etc, will loose their
> functionality because of this shebang line ? Is this not a good general
> reason to use the old one ?
I personally use vim, and it will recognize either shebang, or if none
is present (as in a typical importable module) it will notice the file
suffix, .py. It's not an issue.
More information about the Python-list