python shebangs 与 /usr/bin/env 而不是硬路径有什么区别?
我以前用shebang
#!/usr/bin/env python
什么时候用比较好
#!/usr/bin/python
它们之间的具体区别是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#!/usr/bin/python
被硬编码为始终运行/usr/bin/python
,而#!/usr/bin/env python
> 将运行当前环境中默认的python
(它将考虑例如$PATH
,您可以检查将使用哪个 python 解释器哪个 python
)。第二种方式(
#!/usr/bin/env python
)是首选,因为它不依赖于特定的安装。例如,它将适用于没有/usr/bin/python
的virtualenv
设置或系统,但只有/usr/local/bin/python< /代码>。
#!/usr/bin/python
is hardcoded to always run/usr/bin/python
, while#!/usr/bin/env python
will run whicheverpython
would be default in your current environment (it will take in account for example$PATH
, you can check which python interpreter will be used withwhich python
).The second way (
#!/usr/bin/env python
) is preferred , as it's not dependent on particular installation. It will work for example withvirtualenv
setups or systems where there is no/usr/bin/python
, but only e.g./usr/local/bin/python
.