#/usr/bin/env python and #!/usr/local/bin/python

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)

Hope this helps.

--
Senthil

from http://mail.python.org/pipermail/tutor/2007-June/054816.html

你可能感兴趣的:(Python)