为什么OSX无法运行我在whereis python中获得的python [英] Why is OSX not running the python I get with whereis python
问题描述
我有一台运行OSX Yosemite的机器(它已经通过了多个OSX版本,这可能有所不同).
I have a machine running OSX Yosemite (it has been through several versions of OSX, which may make a difference).
我注意到python是否可以导入库取决于一个脚本是否直接运行,即
I noticed an anomily with whether python could import libraries depending on whether the script was run directly, i.e.
./Myscript.py
或者通过明确调用python
Or by expressly calling python
python Myscript.py
现在,如果我输入
$whereis python
/usr/bin/python
我在剧本中的shebang行是
And my shebang line in the script is
#!/usr/bin/python
所以我假设在两种情况下都运行相同版本的python.
So I assumed that the same version of python was running in both cases.
但是经过调查,我发现
$python --version
Python 2.7.6
$/usr/bin/python --version
Python 2.7.10
所以看起来执行Python并不是我执行whereis时得到的
So it would seem that the python being executed is not the one I get when I do a whereis
任何人都可以对此进行阐明,并阐明如何解决该问题吗?我真的想在两种情况下都运行2.7.10,因为现在安装库时它们进入2.7.6,但是当我运行脚本时,它们运行2.7.10并且看不到库.
Can anyone please shed some light on this, and also clarify how to fix it? I really want to be running 2.7.10 in both cases, since right now when I install libraries they go into 2.7.6, but when I run scripts, they run 2.7.10 and can't see the libraries.
谢谢
乔恩
推荐答案
不要使用whereis
,该命令会忽略您的PATH
环境变量.在联机帮助页上:
Don't use whereis
, that command ignores your PATH
environment variable. From the manpage:
whereis
实用程序检查指定程序的 标准二进制目录 ,并打印出找到的所有路径.
The
whereis
utility checks the standard binary directories for the specified programs, printing out the paths of any it finds.
强调我的.
您有一个PATH
环境变量,其中包括一个非标准"二进制目录.使用which
查找python
的来源:
You have a PATH
environment variable that includes a 'nonstandard' binary directory. Use which
to find where python
comes from:
$ which python
which
为您提供当前外壳配置使用的实际二进制文件:
which
gives you the actual binary used for your current shell configuration:
which
实用程序获取命令名称列表,并在每个可执行文件 的路径下搜索,如果这些命令实际被调用,将运行该文件.
The
which
utility takes a list of command names and searches the path for each executable file that would be run had these commands actually been invoked.
您可以使用which -a
查找命令的所有可能的补全:
You could use which -a
to find all possible completions for the command:
$ which -a python
另请参见 "whereis"和哪个"在超级用户的Mac OS X中返回不同的路径 .
演示:
$ PATH=/opt/homebrew/bin:$PATH whereis python
/usr/bin/python
$ PATH=/opt/homebrew/bin:$PATH which -a python
/opt/homebrew/bin/python
/usr/bin/python
因此,即使PATH
明确地指向我的自制目录,whereis
也会忽略它. which
找到并首先列出它(-a
参数使它寻找更多选项).
So even with PATH
explicitly pointing to my homebrew directory, whereis
ignores it. which
finds it and lists it first (the -a
argument made it look for more options).
这篇关于为什么OSX无法运行我在whereis python中获得的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!