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

Robert Kern robert.kern at gmail.com
Fri May 2 16:15:07 EDT 2008


Yves Dorfsman wrote:
> On UNIX, some people use
> #!/usr/bin/env python
> 
> While other use
> #!/usr/bin/python
> 
> Why is one preferred over the other one ?

Caveat: I've only read *most* of this thread, so maybe someone else has already 
made the following point.

It depends on the context. Ultimately, when your script is installed, it (almost 
certainly) should point to the precise Python executable the installer intends 
it to run on. One of the features of distutils is that it will *rewrite* 
"#!/usr/bin/env python" to use the exact executable that the installer used to 
execute the setup.py.

So *as a developer* I recommend writing your scripts with "#!/usr/bin/env 
python". This lets distutils select the correct executable, and it lets your 
users play around with your scripts prior to installation without needing to 
rewrite the shebang line manually. I hate trying out someone's code just to find 
that that they hardcoded /usr/local/bin/python2.3. If you aren't using distutils 
to install for some reason, you might want to recommend that the installer 
change the shebang line in your installation instructions.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list