开发者

What's the difference between python shebangs with /usr/bin/env rather than hard-path?

开发者 https://www.devze.com 2023-02-27 11:19 出处:网络
I used to use the shebang #!/usr/bin/env python When is it better to use #!/usr/bin/python What is the exact difference be开发者_Go百科tween them?#!/usr/bin/python is hardcoded to always run /u

I used to use the shebang

#!/usr/bin/env python

When is it better to use

#!/usr/bin/python

What is the exact difference be开发者_Go百科tween them?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消