What does "#!/usr/bin/env python" do?

Erik Max Francis max at alcyone.com
Mon Nov 10 10:31:34 CET 2003


Parzival wrote:

> It further tuns out that I have no control over the placement of
> entries
> in PATH, so that my .bash_profile login script which adds
> /usr/local/bin to
> the PATH, wherein are "python", "python2.3" and "idle", does not have
> precedence over the Mandrake installed /usr/bin, wherein are "python"
> and
> "idle". The result is that I must type "python2.3 myscript.py" or
> "/usr/local/bin/idle myscript.py", and the just explained
> "#!/usr/bin/env
> python" at the start of scripts always resolves in favour of the
> Mandrake
> installed Python, not my own current version.

Yes, unfortunately this is the fault of the #!/usr/bin/env solution
(neglecting that in very rare cases env may not be located in /usr/bin).
If multiple Python interpreters are installed, or the same script are
run with rather different environments, then it's hard to say which
interpreter will get caught.  For instance, cron jobs often run with
PATH=/bin:/usr/bin only, in which case they wouldn't ever find a python
in /usr/local/bin, unless you told it to do so.

> I would like my personal installation of Python to be the default and
> convenient version, i.e. "./Myscript.py" "python MyScript.py" and
> "idle"
> should resolve that instead of the system version. Is there a good way
> to
> accomplish this?

The best way to do it for your use is to put the place where you want it
found first in your PATH, or invoke the specific interpreter you want
directly.

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ Human love is often but the encounter of two weaknesses.
\__/  Francois Mauriac




More information about the Python-list mailing list