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

前端 未结 4 1067
无人共我
无人共我 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条回答
  •  别那么骄傲
    2021-02-08 12:01

    As you note, they probably both work on linux. However, if someone has installed a newer version of python for their own use, or some requirement makes people keep a particular version in /usr/bin, the env allows the caller to set up their environment so that a different version will be called through env.

    Imagine someone trying to see if python 3 works with the scripts. They'll add the python3 interpreter first in their path, but want to keep the default on the system running on 2.x. With a hardcoded path that's not possible.

提交回复
热议问题