python - 在 Mac OSX 上安装 pandas 和 numpy 时出现问题

标签 python macos python-2.7 numpy

在获得 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

最佳答案

从更清洁的方式开始。我建议研究像 pyenv 这样的工具和 virtualenv如果您要使用 Python 进行大量工作,尤其是安装其他软件包时。 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

关于python - 在 Mac OSX 上安装 pandas 和 numpy 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18490419/

相关文章:

python - 仅给出子列表的元素(Python),查找列表中元素的索引的最有效方法是什么

python - 装饰器错误 : NoneType object is not callable

python - jupyter-notebook:循环打印精细表格

C++,Code::Blocks,我应该为 windows 和 macos 中的 GUI 选择哪种项目类型?

Python 2.7,z分数计算

ios - CodeSign 问题 : resource-rules (deprecated in Mac OS X >= 10. 10)

c++ - gdb os x sierra 10.12.3 不工作

javascript - 使用 Appcelerator 将基于 web2py 的 Web 应用程序转换为 native 应用程序,容易吗?可能的?

python - Pandas Dataframe 添加缺少的时间戳行,然后向前填充以前的值

python - 如何在两个不同的模型中插入数据?