#!/ usr / bin / python或#!/ usr / bin / env python? [英] #!/usr/bin/python or #!/usr/bin/env python?
问题描述
我理解其中的区别,但是我很好奇是否有人对使用其他人有强烈的感情?我正在读一下
的一般用法(即env)的缺点是它在路径上找到了第一个python的第一个python,这可能不是正确的使用。我不知道大部分时间这是不是真正的问题,但至少需要考虑一下这个问题。
并且在/ usr / bin以外的目录中找到的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. I
don''t know if that''s a real issue most of the time, but it''s at least
something to consider.
And is Python found in directories other than /usr/bin often enough to
justify using the more general form?
推荐答案
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
这篇关于#!/ usr / bin / python或#!/ usr / bin / env python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!