Numpy.dtype的大小不正确,请尝试重新编译

2024-09-24 02:13:40 发布

您现在位置:Python中文网/ 问答频道 /正文

导入熊猫时,我将得到以下错误:

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


Tags: pipthe版本numpy编辑pandassizeos
3条回答

我以前见过这个错误,它通常与熊猫引用旧版本的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版本(为了安全起见,将它移到一个_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是一个很好的方法。但我认为对于你只想让熊猫和小猫咪玩得很好的情况,这种方法应该会很好。

你应该试着把你的numpy升级到最新版本。这对我有效。

pip install --upgrade numpy

我也犯了同样的错误。我通过删除现有的numpy并重新安装解决了这个问题。

pip uninstall numpy #it will remove older version of  numpy on your computer
pip install numpy   #it will install recent version of numpy

实际上,我不知道为什么会这样。我刚换了新版本。

相关问题 更多 >