What's the difference between these two python shebangs

吃可爱长大的小学妹 提交于 2019-12-18 09:59:03

问题


I used to use the shebang

#!/usr/bin/env python

When is it better to use

#!/usr/bin/python

What is the exact difference between them?


回答1:


#!/usr/bin/python is hardcoded to always run /usr/bin/python, while #!/usr/bin/env python will run whichever python would be default in your current environment (it will take in account for example $PATH, you can check which python interpreter will be used with which python).

The second way ( #!/usr/bin/env python ) is preferred , as it's not dependent on particular installation. It will work for example with virtualenv setups or systems where there is no /usr/bin/python, but only e.g. /usr/local/bin/python.



来源:https://stackoverflow.com/questions/5709616/whats-the-difference-between-these-two-python-shebangs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!