avoiding long paths to interpreter

Tim Cargile tecargile at hotmail.com
Fri Jan 17 06:38:42 EST 2003


Erik Max Francis <max at alcyone.com> wrote in message news:<3E1CD949.15CD3DCF at alcyone.com>...
> Mike Meyer wrote:
> 
> > The recommended approach is to use:
> > 
> > #!/usr/bin/env python
> > 
> > which will find python no matter where it is if it's in the users
> > path.
> 
> To be pedantic, you've no guarantee that env will be in /usr/bin
> (although granted that it will be the vast majority of the time).  The
> real wart here is that if you have multiple interpreters installed, say,
> in /usr/bin and /usr/local/bin, then /usr/bin/env picks the python
> that's associated with your PATH.  This can lead to bad surprises if the
> script runs in an interactive shell vs., say, a CGI script or a cron
> job, where the PATHs are almost certain to be far more restrictive,
> particularly if you have a highly customized interactive shell.
> 
> Unfortunately, there's truly no magic bullet here when the script itself
> depends on a certain version of Python.

Yes.  I don't believe in magic either - bullets or otherwise.
All I can say is that the use of '#!/usr/bin/env ...' seems
pervasive and predominant - at least in 2.2.2 release modules.

Just for grins, I looked at the 2.2.2 source release situation.
Of the 1480 or so '*.py' files in the 2.2.2 source release, 
I found 201 that used '#!/usr/bin/env python'. One (Lib/reconvert.py)
used '#!/usr/bin/env python1.5'.

There were only 14 that did not use '#!/usr/bin/env'.  These used one of
the following absolute paths:

   #!/usr/bin/python
   #!/usr/local/bin/python
   #!/usr/local/bin/python2.1

Wonder what's up with these?

Tim




More information about the Python-list mailing list