avoiding long paths to interpreter

Erik Max Francis max at alcyone.com
Wed Jan 8 21:07:05 EST 2003


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.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Strange is our situation here upon earth.
\__/ Albert Einstein
    ZOE / http://www.alcyone.com/pyos/zoe/
 A simple Python OpenGL rendering engine.




More information about the Python-list mailing list