#!/usr/bin/python and #!/usr/bin/env python, which support?

前端 未结 4 1070
无人共我
无人共我 2021-02-08 11:35

How should the shebang for a Python script look like?

Some people support #!/usr/bin/env python because it can find the Python interpreter intelligently. Ot

4条回答
  •  -上瘾入骨i
    2021-02-08 12:01

    I use #!/usr/bin/env python as the default install location on OS-X is NOT /usr/bin. This also applies to users who like to customize their environment -- /usr/local/bin is another common place where you might find a python distribution.

    That said, it really doesn't matter too much. You can always test the script with whatever python version you want: /usr/bin/strange/path/python myscript.py. Also, when you install a script via setuptools, the shebang seems to get replaced by the sys.executable which installed that script -- I don't know about pip, but I would assume it behaves similarly.

提交回复
热议问题