python shebang与/usr/bin/env而不是hard-path有什么区别? [英] What's the difference between python shebangs with /usr/bin/env rather than hard-path?

查看:108
本文介绍了python shebang与/usr/bin/env而不是hard-path有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用过shebang

I used to use the shebang

#!/usr/bin/env python

什么时候使用更好

#!/usr/bin/python

它们之间的确切区别是什么?

What is the exact difference between them?

推荐答案

#!/usr/bin/python被硬编码为始终运行/usr/bin/python,而#!/usr/bin/env python将运行任何python,这在您当前的环境中是默认设置(它将以$PATH为例,您可以检查which python将使用哪个python解释器.

#!/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).

首选第二种方法(#!/usr/bin/env python),因为它不依赖于特定的安装.例如,它适用于virtualenv设置或没有/usr/bin/python的系统,而仅适用于/usr/bin/python. /usr/local/bin/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.

这篇关于python shebang与/usr/bin/env而不是hard-path有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆