【问题标题】:sklearn "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminalsklearn“numpy.dtype 的大小错误,请尝试重新编译”在 pycharm 和终端中
【发布时间】:2016-11-06 21:59:06
【问题描述】:

在编译 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 的?
  • 我的猜测是您已经通过包管理器(pip?conda?)安装了 sklearn,并且您使用的是系统的默认 numpy 安装。它应该由pip install --upgrade scikit-learn numpy 修复(其他包管理器类似)。

标签: python numpy scikit-learn


【解决方案1】:

当您使用不兼容的版本时会出现此问题。使用以下命令检查版本:

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

【讨论】:

    【解决方案2】:

    “numpy.dtype 的大小错误,请尝试重新编译”错误意味着 sklearn 是针对比 sklearn 现在尝试导入的 numpy 版本更新的 numpy 编译的。要解决此问题,您需要确保 sklearn 是针对它现在正在导入的 numpy 版本或早期版本编译的。详细解释见ValueError: numpy.dtype has the wrong size, try recompiling

    我从你的路径猜想你正在使用 OSX 系统 Python(OSX 附带的那个,/usr/bin/python)。 Apple 已经修改了这个 Python,使其选择了自己的 numpy 版本,而不是您使用 pip 等安装的任何版本 - 请参阅 https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages 。我强烈建议您切换到 Python.org 或 homebrew Python,以便更轻松地使用依赖于 numpy 的包。

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 2013-07-16
      • 2014-07-30
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      相关资源
      最近更新 更多