【问题标题】:ValueError: numpy.dtype has the wrong size, with import decomposition [duplicate]ValueError:numpy.dtype 的大小错误,带有导入分解[重复]
【发布时间】:2014-10-02 13:50:02
【问题描述】:

我正在尝试使用 sclearn.decomposition,但出现以下错误:

Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin

>>> import sklearn, numpy,scipy
>>> sklearn.__version__
'0.15.1'
>>> numpy.__version__
'1.6.2'
>>> scipy.__version__
'0.11.0'
>>> 
>>> from sklearn import decomposition
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/sklearn/decomposition/__init__.py", line 7, in <module>
    from .nmf import NMF, ProjectedGradientNMF
  File "/Library/Python/2.7/site-packages/sklearn/decomposition/nmf.py", line 21, in <module>
    from ..utils import atleast2d_or_csr, check_random_state, check_arrays
  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

我尝试使用 pip 卸载和安装所有软件包。不确定还有什么可以尝试的建议?

更新:

结果我安装了旧版本的 numpy/scipy 我手动删除了它们,但现在我收到以下运行时错误:

/Library/Python/2.7/site-packages/scipy/stats/_continuous_distns.py:24: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from . import vonmises_cython
/Library/Python/2.7/site-packages/scipy/stats/_continuous_distns.py:24: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from . import vonmises_cython
/Library/Python/2.7/site-packages/scipy/stats/stats.py:188: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from ._rank import rankdata, tiecorrect
/Library/Python/2.7/site-packages/scipy/stats/stats.py:188: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from ._rank import rankdata, tiecorrect
/Library/Python/2.7/site-packages/scipy/spatial/__init__.py:90: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from .ckdtree import *
/Library/Python/2.7/site-packages/scipy/spatial/__init__.py:90: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .ckdtree import *
/Library/Python/2.7/site-packages/scipy/spatial/__init__.py:91: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from .qhull import *
/Library/Python/2.7/site-packages/scipy/spatial/__init__.py:91: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .qhull import *
/Library/Python/2.7/site-packages/scipy/interpolate/interpolate.py:28: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
  from . import _ppoly
/Library/Python/2.7/site-packages/scipy/interpolate/interpolate.py:28: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from . import _ppoly

【问题讨论】:

  • 可能类似于this。否则,您可以随时尝试从源代码安装 scikit-learn,或使用预制的 Python 环境,例如 anaconda。

标签: python numpy scikit-learn


【解决方案1】:

二进制文件似乎有问题。我在使用 pandas 时遇到了同样的错误,我通过卸载 numpy 和 pandas 并再次安装来修复它。

pip uninstall numpy
pip uninstall pandas
pip install pandas==0.13.1

请注意,安装 pandas 也会安装它的依赖项,例如 numpy。

您的 numpy 和 scipy 版本似乎也很旧。尝试更新它们。

【讨论】:

  • 正如更新所述,我卸载(一些手动)并使用 pip 重新安装了所有内容。这些是我安装的最新版本: >>> import numpy, scipy, sklearn, pandas >>> numpy.__version__ '1.8.2' >>> scipy.__version__ '0.14.0' >>> sklearn.__version__ '0.15 .1' >>> pandas.__version__ '0.13.1' 仍然是同样的错误。唯一的解决方案是如果我没有完全卸载它们。有没有办法检查?
  • 您可以尝试通过键入以下命令来定位 numpy: import numpy print numpy 这将为您提供 numpy 所在的路径。然后你需要做的就是移除这个包。希望对你有帮助
猜你喜欢
  • 2017-09-12
  • 2020-09-14
  • 2019-03-06
  • 2013-11-25
  • 2011-10-25
  • 2021-07-16
  • 2019-03-24
  • 2015-08-25
  • 1970-01-01
相关资源
最近更新 更多