我以前见过这个错误,它通常与 pandas 引用旧版本的 numpy.但是,如果您的 python 路径仍然指向旧版本的 numpy,则重新安装可能无济于事。
当你通过 pip 安装 numpy 时,pip 会告诉你它的安装位置。类似的东西
pip install numpy==1.9.2
Requirement already satisfied (use --upgrade to upgrade): numpy==1.9.2 in /Library/Python/2.7/site-packages
Cleaning up...
所以你安装了正确版本的 numpy。但是当你进入 python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc'
>>> numpy.version.version
'1.8.0rc1'
您的路径可能指向不同的 numpy.
我为此找到的最简单的解决方案就是删除不需要的 numpy 版本(为了安全起见,将其移至 _bak 文件夹)
mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_bak
现在当我启动 python 时
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/Library/Python/2.7/site-packages/numpy/__init__.pyc'
>>> numpy.version.version
'1.9.2'
我有我想要的版本。
对于更复杂的工作流程,不同的应用程序可能需要不同版本的各种包,virtualenvs 是一个很好的方法http://docs.python-guide.org/en/latest/dev/virtualenvs/。但是我认为对于您只想让 pandas 和 numpy 玩得很好的情况,这种方法应该可以正常工作。