Why is "#! / Usr / bin / env python" supposedly more correct than just "#! / Usr / bin / python"?

Does anyone know this? I could never find the answer.

+62
python bash
Aug 30 '09 at 2:30
source share
5 answers

If you tend to install python in different and interesting places on your PATH (as in $PATH on typical Unix shells, %PATH on regular Windows systems), using /usr/bin/env will fit your whim (well, on Unix-like environments at least) going directly to /usr/bin/python will not. But losing control of the version of Python your scripts are running on is not a good deal ... if you look at my code, you will most likely start with it, for example, #!/usr/local/bin/python2.5 and not from open and receiving #!/usr/bin/env python - assuming the script is important, I like it to work with the specific version that I tested and develop it, rather than a semi-random one; -).

+63
Aug 30 '09 at 2:36
source share

From wikipedia

Shebangs indicate absolute paths to system executables; this can cause problems with systems that have custom file system layouts

Often / usr / bin / env can be used to circumvent this limitation.

+24
Aug 30 '09 at 2:36
source share

it finds the python executable in your environment and uses this. this is more portable since python may not always be in / usr / bin / python. env is always located in / usr / bin.

+10
Aug 30 '09 at 2:37
source share

It finds "python" also in / usr / local / bin, ~ / bin, / opt / bin, ... or wherever it may hide.

+5
Aug 30 '09 at 2:31
source share
+3
Aug 30 '09 at 2:34
source share



All Articles