Python 2.7上的numpy问题——numpy.dtype的大小不正确
想知道以前是否有人遇到过类似的问题,有什么解决办法吗?在MacOSX上使用Python 2.7Python 2.7上的numpy问题——numpy.dtype的大小不正确,python,macos,python-2.7,numpy,Python,Macos,Python 2.7,Numpy,想知道以前是否有人遇到过类似的问题,有什么解决办法吗?在MacOSX上使用Python 2.7 import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model, datasets # import some data to play with iris = datasets.load_iris() X = iris.data[:, :2] # we only take the first
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model, datasets
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first two features.
Y = iris.target
h = .02 # step size in the mesh
logreg = linear_model.LogisticRegression(C=1e5)
# we create an instance of Neighbours Classifier and fit the data.
logreg.fit(X, Y)
Traceback (most recent call last):
File "/Users/foo/Downloads/PycharmProjects/testLogisticRegressionSimple.py", line 23, in <module>
from sklearn import linear_model, datasets
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
您的代码对我来说运行良好,这表明这是一个环境错误 尝试运行
sudopip安装--升级--强制重新安装numpy sklearn
,看看这是否奏效
如果通过自制软件安装:brew安装--force numpy
(没有sklearn
自制软件包)
如果通过MacPorts安装:
port -f uninstall py27-numpy
port install py27-numpy
(但如果您是通过自制或MacPorts安装的,我建议您卸载(
port-f uninstall py27 numpy | | brew uninstall numpy
)并改为通过pip安装。您的代码对我来说运行良好,这表明这是一个环境错误
尝试运行sudopip安装--升级--强制重新安装numpy sklearn
,看看这是否奏效
如果通过自制软件安装:brew安装--force numpy
(没有sklearn
自制软件包)
如果通过MacPorts安装:
port -f uninstall py27-numpy
port install py27-numpy
(但如果您通过自制或MacPorts安装,我建议卸载(
port-f uninstall py27 numpy | | brew uninstall numpy
)而不是通过pip安装。您的代码对我很有用。可能是您需要重新安装SklearnTanks@James,为什么与sklearn相关?似乎错误与numpy
?请查看以消除该操作系统错误。但是,如果我是您,我会安装miniconda,并安装单独的pythonenvironment@LinMa输出端我的哪个python
是/Users/username/anaconda/bin/python
,我可以很容易地使用matplotlib而不出错。我通过conda install
安装了这个库。此外,我从来不用将sudo与pip
或conda
一起使用,而且我还通过conda install pip
安装了@LinMa我会尝试卸载scikit learn和numpy,只是为了确保同时使用pip和conda。然后尝试仅使用conda安装重新安装,但在这样做之前,确保您对所有内容都有权限trysudo chown-R userdir
您的代码对我有效。可能是您需要重新安装sklearnThanks@James,为什么要重新安装ted to sklearn?似乎错误与numpy
有关?请查看以消除该操作系统错误。但是,如果我是你,我会安装miniconda,并安装单独的pythonenvironment@LinMa我的哪个python
的输出是/Users/username/anaconda/bin/python
,我可以很容易地使用matplotlib而不出现错误。我通过conda install
安装了这个库,而且我从来不用将sudo与pip
或conda
一起使用,而且我还通过conda install pip
安装了pip
@LinMa,我会尝试卸载sciket learn和numpy,只是为了确保同时使用pip和conda。然后尝试用co重新安装nda只安装,但在安装之前,请确保您对所有内容都有权限尝试sudo chown-R userdir
谢谢Christian,我没有使用自制或MacPorts,只使用OSX的本机Python框架。我尝试了您的命令,遇到了更多奇怪的问题,我将其发布在“编辑1”部分,如果您可以看一下并使用任何comments,这将是伟大的。:)感谢Christian,我没有使用自制或MacPorts,只是使用OSX的原生Python框架。我尝试了您的命令,遇到了更多奇怪的问题,我将其发布在编辑1部分,如果您可以看一看并有任何评论,这将是伟大的。:)