Python script header

后端 未结 6 1912
名媛妹妹
名媛妹妹 2020-12-04 10:54

The typical header should be

#!/usr/bin/env python

But I found below also works when executing the script like $python ./my_script.p

6条回答
  •  日久生厌
    2020-12-04 11:10

    The /usr/bin/env python becomes very useful when your scripts depend on environment settings for example using scripts which rely on python virtualenv. Each virtualenv has its own version of python binary which is required for adding packages installed in virtualenv to python path (without touching PYTHONPATH env).

    As more and more people have started to used virtualenv for python development prefer to use /usr/bin/env python unless you don't want people to use their custom python binary.

    Note: You should also understand that there are potential security issues (in multiuser environments) when you let people run your scripts in their custom environments. You can get some ideas from here.

提交回复
热议问题