sklearn在pycharm和终端中出现"numpy.dtype大小不正确,请尝试重新编译"的错误提示。

3

在编译Sci-kit学习时,我在pycharm和终端中都收到了"numpy.dtype大小不正确,请尝试重新编译"的错误提示。我已经将所有包(numpy,scikit)升级到最新版本,但仍然不能解决问题。Python版本为2.7。请帮忙解决。谢谢!

    checking for nltk
    Traceback (most recent call last):
    File "startup.py", line 6, in <module>
    import nltk
      File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
      from nltk.chunk import *
      File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
   from nltk.chunk.api import ChunkParserI
  File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
    from nltk.parse import ParserI
  File "/Library/Python/2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
    from nltk.parse.transitionparser import TransitionParser
  File "/Library/Python/2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
    from sklearn.datasets import load_svmlight_file
  File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
    from .utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
    from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling

你是如何安装scikit和numpy的? - BrenBarn
我的猜测是您通过软件包管理器(pip?conda?)安装了sklearn,并且正在使用系统的默认numpy安装。应该通过pip install --upgrade scikit-learn numpy(其他软件包管理器类似)来解决这个问题。 - Imanol Luengo
2个回答

1
"numpy.dtype has the wrong size, try recompiling"这个错误意味着sklearn是根据比它现在尝试导入的numpy更近期的版本进行编译的。要解决此问题,您需要确保sklearn是针对它现在导入的numpy版本或更早版本进行编译的。详细解释请参见ValueError: numpy.dtype has the wrong size, try recompiling
从您的路径推断,我猜您正在使用OSX系统Python(随OSX一起提供的那个,在/usr/bin/python)。苹果已经以一种使其捕获自己版本的numpy而不是您使用pip等安装的任何版本的numpy的方式修改了此Python,请参见https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages。我强烈建议您切换到Python.org或homebrew Python,以便更轻松地处理依赖于numpy的软件包。"

0
问题发生在使用不兼容版本时。使用以下命令检查版本:
pip freeze

或者针对特定模块

pip freeze | grep Module_Name

我通过更新所有的软件包来解决了我的问题:

pip install -U scikit-learn numpy scipy pandas matplotlib

截止至今天(2016年11月30日),这些版本是兼容的:
matplotlib==1.5.2
nltk==3.2.1
numpy==1.11.2
pandas==0.19.1
scikit-learn==0.18.1
scipy==0.18.1
textblob==0.11.1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接