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

Bill Campbell bill at celestial.net
Thu Jun 14 21:55:35 CEST 2007


On Thu, Jun 14, 2007, Rolando Pereira wrote:
>Senthil_OR at Dell.com escreveu:
>> Okay, I guess, people are missing points here. 
>>  
>> When do you
>>  
>> #!/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)
>>  
...
>I've always used #!/usr/bin/python...
>
>Perhaps I should use the "#!/usr/bin/env python" one.

The case where ``#!/usr/bin/env python'' won't work is where
there are multiple versions of python on the system, and one
wants to run a version that's not first in the PATH.  In that
case one needs to put the full path to the proper executable.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

``The trouble with fighting for human freedom is that one spends most of
one's time defending scoundrels. For it is against scoundrels that
oppressive laws are first aimed, and oppression must be stopped at the
beginning if it is to be stopped at all.'' -- H. L. Mencken


More information about the Tutor mailing list