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

Duncan Booth duncan.booth at invalid.invalid
Fri May 2 03:54:04 EDT 2008


Yves Dorfsman <yves at zioup.com> wrote:

> On UNIX, some people use
> #!/usr/bin/env python
> 
> While other use
> #!/usr/bin/python
> 
> Why is one preferred over the other one ?
> 
I don't think the answers so far have communicated what I believe to be the 
important point: it isn't that one is always better than the other, it 
depends on what you are trying to achieve.

The first one runs the Python found from the environment. This means you 
can write a script and expect it to run on systems configured differently. 
You might prefer in some cases to specify a particular version of Python:

#!/usr/bin/env python2.5

The second one runs a specific copy of Python (and here it is even more 
likely that you'll want to specify a particular version). This is important 
if your program is being run as a service or some other background 
situation where the environment isn't set up. For example Subversion hooks 
all run with an empty environment, and cron jobs run with a default 
environment which may not include python (e.g. if it is in /usr/local/bin).





More information about the Python-list mailing list