【问题标题】:Mac Lion Python modules - not installing in the right locationMac Lion Python 模块 - 未安装在正确的位置
【发布时间】:2013-02-28 08:42:53
【问题描述】:

我正在尝试升级我的一些 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

$PYTHONPATH:

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

似乎奏效了!

【问题讨论】:

  • 输入which python并发布结果。
  • matty$ which python /opt/local/bin/python
  • 您是否配置了$PYTHONPATH
  • 我不确定,是 sys.path 的东西吗?
  • 不,只是 echo $PYTHONPATH 在你的 shell 中。

标签: python macos osx-lion


【解决方案1】:

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

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

一旦确认,只需找出$PYTHONPATH 的设置位置(可能是~/.profile~/.bash_profile/etc/profile)并将其删除。

【讨论】:

    猜你喜欢
    • 2017-05-31
    • 2013-08-26
    • 1970-01-01
    • 2021-06-28
    • 2016-02-27
    • 1970-01-01
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多