#!/usr/bin/env python vs. #!/usr/bin/python
Roy Smith
roy at panix.com
Fri May 2 00:16:05 EDT 2008
In article <87abj91j8u.fsf at benfinney.id.au>,
Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> 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.
You've got it exactly.
I'm currently using Python to write unit tests as part of a build system.
Many of our development boxes don't have python installed in /usr/bin (or
perhaps at all). And even if they did, we might want to use a different
version of Python on different branches of the code.
We've got Python built for all our platforms and the binaries stored in our
source control system. When you check out a particular branch, you get the
right version of Python for that branch. By having the Python scripts
start with #!/usr/bin/env python, I can select the version of Python I want
just by changing the environment.
Then, of course, I recently ran across a machine where env was installed in
/opt/gnu/bin instead of /usr/bin. Sigh. Sometimes you just can't win.
More information about the Python-list
mailing list