且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

#!/ usr / bin / python或#!/ usr / bin / env python?

更新时间:2023-01-14 21:44:44

John Salerno写道:
John Salerno wrote:

我理解差异,但我只是好奇,如果有人有任何

对使用其中一个的强烈感受?我正在读一下

的一般用法(即env)的缺点是它在路径上找到了第一个python的第一个python,这可能不是正确的使用。
I understand the difference, but I''m just curious if anyone has any
strong feelings toward using one over the other? I was reading that a
disadvantage to the more general usage (i.e. env) is that it finds the
first python on the path, and that might not be the proper one to use.



我看不出与
/ usr / bin / python中的Python有什么不同是正确的使用方法。我知道我的

大学的确如此:

I don''t see how that''s any different from when the Python at
/usr/bin/python isn''t the right one to use. I know that''s true at my
university:


/ usr / bin / python -V

Python 2.2.3
/usr/bin/python -V
Python 2.2.3


/ usr / local / python / bin / python -V

Python 2.4.3 >

使用此设置,/ usr / bin中的一个用于操作系统,很少更新
,而/ usr / local中的那个用于用户,并且经常更新。


当然,如果有人没有将/ usr / local / python / bin放在他们的路径上,

他们不会去获得正确的Python,但我不再编写代码来支持
Python 2.2,所以如果我使用``#!/ usr / bin / python``我的代码将会是

可能只是失败。


显然,在我自己的代码中,我只使用``#!/ usr / bin / env python``。


STeVe
/usr/local/python/bin/python -V
Python 2.4.3

With this setup, the one in /usr/bin is for the OS and is seldom
updated, and the one in /usr/local is for users and is updated frequently.

Sure, if someone doesn''t put /usr/local/python/bin on their PATH,
they''re not going to get the right Python, but I don''t write code to
Python 2.2 anymore, so if I use ``#!/usr/bin/python`` my code will
probably just fail.

Obviously, in my own code, I only use ``#!/usr/bin/env python``.

STeVe