I used to use the shebang
我以前用过shebang
#!/usr/bin/env python
When is it better to use
什么时候使用更好
#!/usr/bin/python
What is the exact difference between them?
它们之间的确切区别是什么?
1 个解决方案
#1
61
#!/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/python硬编码为总是运行/usr/bin/python,而#!/usr/bin/env python将运行当前环境中默认的任何python(它将考虑例如$PATH,您可以检查哪个python解释器将与哪个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
.
第二种方法(#!/usr/bin/env python)是首选,因为它不依赖于特定的安装。例如,在没有/usr/bin/python的情况下,但是只有/usr/ local/bin/python才可以使用它。
#1
61
#!/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/python硬编码为总是运行/usr/bin/python,而#!/usr/bin/env python将运行当前环境中默认的任何python(它将考虑例如$PATH,您可以检查哪个python解释器将与哪个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
.
第二种方法(#!/usr/bin/env python)是首选,因为它不依赖于特定的安装。例如,在没有/usr/bin/python的情况下,但是只有/usr/ local/bin/python才可以使用它。