在Mac OSX上安装panda和numpy时出现问题



在拿到奥的书之前,我一直在玩Python的pandas包。当我在成功安装xcode和EPDFree后尝试安装panda时,使用easy_install的panda安装出现了许多警告,当我测试panda是否工作时,很明显不是。我尝试过几次删除和重新安装pandas和Numpy,但都没有成功。我是新手,所以我肯定做错了什么。

这是我运行Python并尝试导入pandas和Numpy:时得到的结果

$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> import pandas
No module named numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pandas-0.12.0-py2.7-macosx-10.8-intel.egg/pandas/__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:19547)
ImportError: No module named numpy

有没有办法解决这个问题,或者重新开始整个安装?

以下是我尝试安装pandas和Numpy:时的一些更多信息

$ sudo easy_install pandas
Password:
Searching for pandas
Best match: pandas 0.12.0
Processing pandas-0.12.0-py2.7-macosx-10.8-intel.egg
pandas 0.12.0 is already the active version in easy-install.pth
Using /Library/Python/2.7/site-packages/pandas-0.12.0-py2.7-macosx-10.8-intel.egg
Processing dependencies for pandas
Finished processing dependencies for pandas
$ sudo easy_install numpy
Searching for numpy
Best match: numpy 1.6.1
numpy 1.6.1 is already the active version in easy-install.pth
Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Processing dependencies for numpy
Finished processing dependencies for numpy

从更清洁的方式开始。如果你要用Python做大量的工作,尤其是在安装额外的软件包时,我建议你研究pyenv和virtualenv这样的工具。Pyenv使您能够轻松管理多个版本并在多个版本之间切换(包括微型版本x.x.3、x.x.5等)。Virtualenv允许您创建独立的Python环境,在那里您可以确定特定项目的站点包版本。

它将类似于:

只是使用virtualenv:

$ pip install virtualenv
$ virtualenv foo
$ source foo/bin/activate
$ pip install pandas
$ pip install numpy

或者,使用pyenv+virtualenv(用于对Python版本的额外控制,例如指定2.7.2),首先安装pyenv,然后:

$ pip install virtualenv
$ pyenv install 2.7.2
$ pyenv shell 2.7.2
$ virtualenv `which python` foo
$ source foo/bin/activate    
$ pip install pandas
$ pip install numpy

请注意启动正确的python版本。如果您使用的是brew版本:which python应该返回/usr/local/bin

如果不是这样,请检查.bash_profile.中的$PATH环境变量

这对我很有效。我想使用easy_install与brew和pip类似。

最新更新