导入pandas时会出现以下错误:
Numpy.dtype has the wrong size, try recompiling
我正在运行Python 2.7.5,Pandas 0.14.1和Numpy 1.9.0。我尝试使用pip安装两者的旧版本,每次都有重大错误。我是Python的初学者,所以任何帮助都会非常感激。 :)
编辑:运行OS X 10.9.4
编辑2:这是我卸载并重新安装Numpy + Pandas,然后运行.py文件的视频的链接:https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov?dl=0
答案 0 :(得分:19)
我之前看过这个错误,它通常与引用旧版numpy的pandas有关。但是,如果你的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/。但我认为,对于你只想要大熊猫和numpy玩得很好的情况,这种方法应该可以正常工作。
答案 1 :(得分:5)
我得到了同样的错误。我通过删除现有的numpy解决了并重新安装。
pip uninstall numpy #it will remove older version of numpy on your computer
pip install numpy #it will install recent version of numpy
实际上我不知道它为什么会起作用。我只是改变了numpy版本。
答案 2 :(得分:2)
你应该尝试将你的numpy升级到最新版本。它对我有用。
pip install --upgrade numpy