Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?


Question

Anyone know this? I've never been able to find an answer.

1
68
8/30/2009 2:30:30 AM

Accepted Answer

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;-).

66
8/30/2009 2:36:51 AM

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


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon