[Tutor] "#!/usr/bin/env python" vs "#!/usr/local/bin/python"

wesley chun wescpy at gmail.com
Thu Jun 14 20:13:07 CEST 2007


> Okay, I guess, people are missing points here.
>
> #!/usr/local/bin/python
> You are specifying the location to the python executable in your machine,
> that rest of the script needs to be interpreted with.
> You are pointing to python is located at /usr/local/bin/python
>
> Consider the possiblities that in a different machine, python may be
> installed at /usr/bin/python or /bin/python in those cases, the above #!
> will fail.
> For those cases, we get to call the env executable with argument which will
> determine the arguments path by searching in the $PATH and use it correctly.
>
> Thus,
> #/usr/bin/env python
> Will figure out the correct location of python ( /usr/bin/python or
> /bin/python from $PATH) and make that as the interpreter for rest of the
> script.
> - ( env is almost always located in /usr/bin/ so one need not worry what is
> env is not present at /usr/bin)


senthil is correct in this regard.  the bottom line is that the one
with env is more flexible and will run on more systems and more types
of systems because it uses the "env" command to find where python is
located and executes it.

the other one simply will *not* work if python is not installed in
that exact location.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list