Python numpy.dtype大小不对,重新编译试试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26067692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:00:17  来源:igfitidea点击:

Numpy.dtype has the wrong size, try recompiling

pythonnumpypandas

提问by Alexander Molloy

When importing pandas I would get the following error:

导入熊猫时,我会收到以下错误:

Numpy.dtype has the wrong size, try recompiling

Numpy.dtype has the wrong size, try recompiling

I am running Python 2.7.5, with Pandas 0.14.1, and Numpy 1.9.0. I have tried installing older versions of both using pip, with major errors every time. I am a beginner when it comes to Python so any help here would be much appreciated. :)

我正在运行 Python 2.7.5、Pandas 0.14.1 和 Numpy 1.9.0。我曾尝试使用 pip 安装旧版本,但每次都出现重大错误。我是 Python 的初学者,因此非常感谢这里的任何帮助。:)

EDIT: running OS X 10.9.4

编辑:运行 OS X 10.9.4

EDIT 2: here is a link to a video of me uninstalling and reinstalling Numpy + Pandas, and then running a .py file: https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov?dl=0

编辑 2:这是我卸载并重新安装 Numpy + Pandas,然后运行 ​​.py 文件的视频链接:https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov ?dl =0

采纳答案by Dan Frank

I've seen this error before and it typically does have to do with pandas referencing an old version of numpy. But reinstalling may not help if your python path is still pointing to an old version of numpy.

我以前见过这个错误,它通常与引用旧版本 numpy 的熊猫有关。但是,如果您的 python 路径仍然指向旧版本的 numpy,则重新安装可能无济于事。

When you install numpy via pip, pip will tell you where it was installed. Something like

当您通过 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...

So you have the correct version of numpy installed. But when you go into python

所以你安装了正确版本的 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'

Your path might be pointing at a different numpy.

您的路径可能指向不同的 numpy。

Easiest solution I've found for this is simply to remove the unwanted version of numpy (moving it to a _bak folder for safety)

我为此找到的最简单的解决方案就是删除不需要的 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

And now when I start python

现在当我开始 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'

I've got the version I want.

我有我想要的版本。

For more complex workflows where different applications might need different versions of various packages, virtualenvs are a great way to go http://docs.python-guide.org/en/latest/dev/virtualenvs/. But I think for your case where you just want pandas and numpy to play nice, this approach should work fine.

对于更复杂的工作流,其中不同的应用程序可能需要不同版本的各种包,virtualenvs 是一个很好的方式去http://docs.python-guide.org/en/latest/dev/virtualenvs/。但是我认为对于您只希望 pandas 和 numpy 发挥良好作用的情况,这种方法应该可以正常工作。

回答by Harun ERGUL

I got same error. I solved by deleting existing numpy and reinstall again.

我有同样的错误。我通过删除现有的 numpy 并重新安装来解决。

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

Actually I don't have any idea why it works. I just changed numpy version.

其实我不知道为什么它有效。我刚刚更改了numpy版本。

回答by avinash gupta

you should try to upgrade your numpy to latest. it worked for me.

您应该尝试将 numpy 升级到最新版本。它对我有用。

pip install --upgrade numpy