Skip to main content
 首页 » 编程设计

python之Mac Lion Python 模块之没有安装在正确的位置

2025年05月04日8exmyth

我正在尝试升级我的一些 Python 模块 - 特别是:matplotlib、scipy 和 numpy。

我试过使用 macports 和 easy_install 但没有成功。我认为它们安装在错误的位置..

从 macports 我得到:

matty$ port installed 
......... snip ......... 
py27-ipython @0.13.1_0+scientific (active) 
py27-matplotlib @1.2.0_1+tkinter (active) 
py27-numpy @1.6.2_1 (active) 
python27 @2.7.3_1 (active) 

据我在 macports 上看到的,我安装了 matplotlib 1.2 版和 numpy 1.6 版。但是,当我检查 Python 时,我得到:

matty$ python --version 
Python 2.7.3 
 
matty$ python 
>>> import numpy 
>>> print numpy.__version__ 
1.5.1 
 
>>> import matplotlib 
>>> print matplotlib.__version__ 
1.0.1 

使用 easy_install 我遇到一些沙箱错误:

matty$ sudo easy_install -U numpy 
......... snip ......... 
error: SandboxViolation: open('/dev/null', 'w') {} 

我猜某处存在 PATH 错误 - 这是一个猜测!任何帮助深表感谢。

编辑:

matty$ which python 
/opt/local/bin/python 

这是一个链接:

matty$ ls -l python 
lrwxr-xr-x  1 root  admin  24 27 Feb 13:34 python -> /opt/local/bin/python2.7 
matty$ ls -l python2.7 
lrwxr-xr-x  1 root  admin  73 22 Oct 21:14 python2.7 ->    
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 

$Python路径:

matty$ echo $PYTHONPATH 
/usr/local/scisoft/packages/python/lib/python2.6/site-packages/ 

这样做:

matty$ export PYTHONPATH= 
 
matty$ python 
>>> import numpy 
>>> print numpy.__version__ 
1.6.2 
>>> import matplotlib 
>>> print matplotlib.__version__ 
1.2.0 

似乎成功了!

请您参考如下方法:

您将环境变量 $PYTHONPATH 设置为非标准位置(在 Macports Python 安装目录之外)。

如果您清除 $PYTHONPATH,那么您的测试将会工作。

一旦你确认了这一点,这只是找出 $PYTHONPATH 设置位置的一个例子(可能是 ~/.profile,~/.bash_profile 或 /etc/profile) 并将其删除。