【问题标题】:Problems installing pandas and numpy on Mac OSX在 Mac OSX 上安装 pandas 和 numpy 时出现问题
【发布时间】:2013-08-31 16:12:25
【问题描述】:

在拿到 O'Reilly 的书之前,我在玩 Python 的 pandas 包。当我在成功安装 xcode 和 EPDFree 后尝试安装 pandas 时,使用 easy_install 安装 pandas 时出现了许多警告,当我测试 pandas 是否正常工作时,很明显不是。我曾多次尝试删除并重新安装 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 macos python-2.7 numpy


    【解决方案1】:

    从更清洁的方式开始。如果您打算使用 Python 进行任何数量的工作,尤其是在安装其他软件包时,我建议您研究像 pyenvvirtualenv 这样的工具。 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),首先 install 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
    

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2013-11-06
        • 2011-07-08
        • 1970-01-01
        • 1970-01-01
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 2019-05-27
        • 2015-04-23
        相关资源
        最近更新 更多