Anyone know this? I've never been able to find an answer.
- 4not a ton. i'm on osx and the env manpage is rather ambiguous there.Kenneth Reitz– Kenneth Reitz2009-08-30 02:37:35 +00:00Commented Aug 30, 2009 at 2:37
- 16@S.Lott: Have you read it lately? On my Debian box, it's one of the most unhelpful man pages I've ever seen, and that's saying something. (Here's the whole "Description": Set each NAME to VALUE in the environment and run COMMAND. Yup, that would clear him right up.)Telemachus– Telemachus2009-08-30 02:42:31 +00:00Commented Aug 30, 2009 at 2:42
- @Telemachus: Yes, I did read it. It's why I found the Wikipedia entry.S.Lott– S.Lott2009-08-30 02:44:39 +00:00Commented Aug 30, 2009 at 2:44
- 4One problem with env is that you can't add -u or any other option to be passed to the python executableArkady– Arkady2009-08-30 02:56:17 +00:00Commented Aug 30, 2009 at 2:56
- 1Also a very good answer on a very related Unix SE question is here.Albert– Albert2012-11-28 00:46:40 +00:00Commented Nov 28, 2012 at 0:46
5 Answers
If you're prone to installing python in various and interesting places on your PATH (as in $PATH in typical Unix shells, %PATH on typical Windows ones), using /usr/bin/env will accomodate your whim (well, in Unix-like environments at least) while going directly to /usr/bin/python won't. But losing control of what version of Python your scripts run under is no unalloyed bargain... if you look at my code you're more likely to see it start with, e.g., #!/usr/local/bin/python2.5 rather than with an open and accepting #!/usr/bin/env python -- assuming the script is important I like to ensure it's run with the specific version I have tested and developed it with, NOT a semi-random one;-).
6 Comments
#!/usr/bin/env python and virtualenvs will execute the script in current venv! This may or may not be a good thing, depends on your use case.From wikipedia
Shebangs specify absolute paths to system executables; this can cause problems on systems which have non-standard file system layouts
Often, the program /usr/bin/env can be used to circumvent this limitation
Comments
it finds the python executable in your environment and uses that. it's more portable because python may not always be in /usr/bin/python. env is always located in /usr/bin.
1 Comment
It finds 'python' also in /usr/local/bin, ~/bin, /opt/bin, ... or wherever it may hide.
5 Comments
/usr/bin/env does not exist, your system is broken. envis a required tool by POSIX standard.You may find this post to be of interest: http://mail.python.org/pipermail/python-list/2008-May/661514.html
This may be a better explanation: http://mail.python.org/pipermail/tutor/2007-June/054816.html