#!/usr/bin/env python vs. #!/usr/bin/python

Grant Edwards grante at visi.com
Fri May 2 10:40:10 EDT 2008


On 2008-05-02, Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:

> The specified command takes the form of a fully-qualified file
> path, and zero or one arguments to the program. That command
> is then executed by the kernel, and the Python program file is
> passed as input to the resulting process.

Just to clarify that a bit a little, the name of the file (as
it was given to the "exec" system call) containing the "shebang
line" is passed to the resulting process as a command-line
parameter.

>> Why is one preferred over the other one ?
>
> I've never clearly understood why people want to use "#! /usr/bin/env
> python", which is prone to finding a different Python from the one
> installed by the operating system. I'd be interested to see what
> responses are in favour of it, and what the reasoning is.
>
> One possible reason is that the programmer is attempting to allow for
> systems where Python has been installed, but not from an operating
> system package.

Exactly.  the "env" approach works as long as python is
installed somewhere on the PATH.  "#!/usr/bin/python" will fail
if python is installed in /usr/local/bin/python.

-- 
Grant




More information about the Python-list mailing list