python shebang与/usr/bin/env而不是hard-path有什么区别? [英] What's the difference between python shebangs with /usr/bin/env rather than 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屋!