简体   繁体   English

机器学习代码中的numpy.dtype错误(Python)

[英]numpy.dtype error in machine learning code (Python)

I am just trying to run a scikit-learn example source code successfully, but am getting an consistent error. 我只是尝试成功运行scikit-learn示例源代码,但是遇到了一致的错误。 The code can be found here - it has around 90 lines of code, so it wouldn't be efficient to put it in here. 可以在此处找到该代码-它包含大约90行代码,因此将其放在此处效率不高。 However, whenever I run it, I get the error message called from the Import sklearn stating: 但是,无论何时运行它,我都会从Import sklearn收到一条错误消息,说明:

File "plot_outlier_detection.py", line 33, in <module>
  from sklearn import svm
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

The main error is 主要错误是

ValueError: numpy.dtype has the wrong size, try recompiling

and I've looked into many Stackoverflow posts already, saying that I need to update my numpy, matplotlib, scipy, which I've done already multiple times (upgrade / uninstall+install using pip / uninstall+install from source), but the same error still shows up (I also reinstalled sklearn). 并且我已经研究了许多Stackoverflow帖子,说我需要更新我的numpy,matplotlib,scipy,我已经做过多次了(使用pip升级/ uninstall + install /从源代码进行uninstall + install),但是仍然显示相同的错误(我也重新安装了sklearn)。 I think I know why this is the case: 我想我知道为什么会这样:

When I use python in terminal and check the numpy version I get 当我在终端中使用python并检查numpy版本时,我得到了

import numpy
numpy.version.version
'1.9.2'

However, when I try installing or upgrading through pip -- I get the message 但是,当我尝试通过pip安装或升级时,我收到消息

numpy in /Library/Python/2.7/site-packages/numpy-1.11.0-py2.7-macosx-10.10-intel.egg

I read in this Stackoverflow query about this, and they said to use easy_install as python doesn't read from the right path in Macs (IDK, can someone confirm?) so I did it through easy_install, and get this message 我在这个 Stackoverflow查询中读到了有关此内容的内容,他们说要使用easy_install,因为python无法从Mac中正确的路径读取数据(IDK,有人可以确认吗?),所以我通过easy_install进行了操作,并得到了此消息

Searching for numpy
Best match: numpy 1.11.0
Processing numpy-1.11.0-py2.7-macosx-10.10-intel.egg
numpy 1.11.0 is already the active version in easy-install.pth
Installing f2py script to /usr/local/bin

Using /Library/Python/2.7/site-packages/numpy-1.11.0-py2.7-macosx-10.10-intel.egg
Processing dependencies for numpy
Finished processing dependencies for numpy

which is the exact same thing. 这是完全一样的。 I don't really know what's going on. 我真的不知道怎么回事。 Can anyone help me? 谁能帮我?

For reference of versions: 供版本参考:

Python - 2.7.10
Numpy - 1.9.2
Matplotlib - 1.4.3
Scipy - 0.13.0b1

The rest of the versions are also not up to date..but they derive from numpy's version being up-to-date. 其余版本也不是最新的..但是它们来自numpy的最新版本。

I've installed Anaconda (2.5.0) on my Ubuntu (14.04) With Anaconda 2.5.0 my versions are: 我已经在装有Anaconda 2.5.0的Ubuntu(14.04)上安装了Anaconda(2.5.0),我的版本是:

python 2.7.11 python 2.7.11

Numpy 1.10.4 脾气暴躁的1.10.4

Scipy 0.17.0 西皮0.17.0

I've download the code from the link, and it worked perfectly on my machine 我已经从链接下载了代码,并且在我的机器上运行良好

Can you try to install Anaconda and see if it solve your problems? 您可以尝试安装Anaconda并查看它是否可以解决您的问题吗? https://www.continuum.io/downloads https://www.continuum.io/downloads

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM