Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is "#!/usr/bin/env python" the better shebang line ?

Reply
Thread Tools

Is "#!/usr/bin/env python" the better shebang line ?

 
 
Timothy Madden
Guest
Posts: n/a
 
      09-06-2009
Hello

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.

First, can one not find /usr/bin/python in any standard system, at least
as much as /usr/bin/env can be found ?

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 ?

Now I know env is POSIX standard utility, and python is not, and maybe
that could be reason enough, but are there any other issues involved
with using /usr/bin/env ?

Thank you
Timothy Madden
 
Reply With Quote
 
 
 
 
Benjamin Kaplan
Guest
Posts: n/a
 
      09-06-2009
On Sun, Sep 6, 2009 at 10:01 AM, Timothy Madden<(E-Mail Removed)> wrote:
> Hello
>
> 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.
>
> First, can one not find /usr/bin/python in any standard system, at least as
> much as /usr/bin/env can be found ?
>

Not necessarily. The system python (if it exists) is usually in
/usr/bin but what if there is no system-installed Python or the user
would prefer to use a version they compiled themselves and is
therefore in /usr/local/bin? Or what if the system decides /usr/bin is
just for the default system tools and everything else should be
installed in /opt/? env will always be in the same place, but Python
may not be so using env makes it more portable.


> 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 ?
>
> Now I know env is POSIX standard utility, and python is not, and maybe that
> could be reason enough, but are there any other issues involved with using
> /usr/bin/env ?
>
> Thank you
> Timothy Madden
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
 
 
 
Ned Deily
Guest
Posts: n/a
 
      09-06-2009
In article <4aa3bfdf$0$282$(E-Mail Removed)>,
Timothy Madden <(E-Mail Removed)> wrote:
> 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.


This question came up recently on stackoverflow (alas, will result in
urloverflow):

http://stackoverflow.com/questions/1...nv-python-supp
osedly-more-correct-than-just-usr-bin-pyth/1352938#1352938

--
Ned Deily,
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Timothy Madden
Guest
Posts: n/a
 
      09-07-2009
Ned Deily wrote:
> In article <4aa3bfdf$0$282$(E-Mail Removed)>,
> Timothy Madden <(E-Mail Removed)> wrote:
>> 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.

>
> This question came up recently on stackoverflow (alas, will result in
> urloverflow):
>
> http://stackoverflow.com/questions/1...nv-python-supp
> osedly-more-correct-than-just-usr-bin-pyth/1352938#1352938
>

Ok, thank you.
There is quite a flame since May 2008 archived on mail.python.org about
this issue.

#!/usr/bin/env python is clearly the choice for my scripts.

It helps a lot with portability, and the arguments against it are based
on the idea that /usr/bin/python is somehow better than /opt/python and
that /opt/python is still in front of /usr/bin/python in path. Such an
argument I do not find compelling. The thing is that people writing
large applications for many systems need flexibility first.

Timothy Madden
 
Reply With Quote
 
ryles
Guest
Posts: n/a
 
      09-07-2009
On Sep 6, 10:01*am, Timothy Madden <(E-Mail Removed)> wrote:
> Hello
>
> 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".

http://blade.nagaokaut.ac.jp/cgi-bin...by-talk/237208

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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I find the 'shebang' line? Ast Jay Ruby 5 07-27-2010 09:20 PM
Shebang line problems and python Blaine Python 11 09-17-2009 09:24 PM
Shebang! line not recognized in OS X Leopard?? Johnnie Lieske Ruby 6 11-28-2008 02:25 PM
warning flag on shebang line - premature end of script header Prachi Perl Misc 5 05-17-2005 06:44 PM
Optimize flag on shebang line Andres Corrada-Emmanuel Python 0 12-09-2003 07:02 PM



Advertisments