简体   繁体   English

Python 2.7上的numpy问题-numpy.dtype的大小错误

[英]numpy issue on Python 2.7 — numpy.dtype has the wrong size

Wondering if anyone met with similar issues before and any solutions? 想知道是否有人遇到过类似的问题以及任何解决方案? Using Python 2.7 on Mac OSX. 在Mac OSX上使用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 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

Edit 1 , met with errors when trying to re-install, here are the command and error message, 编辑1 ,尝试重新安装时遇到错误,这是命令和错误消息,

sudo /usr/local/bin/pip install --upgrade --force-reinstall numpy sklearn
The directory '/Users/foo/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/foo/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting numpy
  Downloading numpy-1.11.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB)
    100% |████████████████████████████████| 3.9MB 296kB/s
Collecting sklearn
Collecting scikit-learn (from sklearn)
  Downloading scikit_learn-0.17.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB)
    100% |████████████████████████████████| 3.9MB 317kB/s
Installing collected packages: numpy, scikit-learn, sklearn
  Found existing installation: numpy 1.8.0rc1
    DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling numpy-1.8.0rc1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 726, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 746, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-TDvKH6-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Your code works fine for me, which suggests it's an environment error. 您的代码对我来说工作正常,这表明这是环境错误。

Try running sudo pip install --upgrade --force-reinstall numpy sklearn and see if that does the trick. 尝试运行sudo pip install --upgrade --force-reinstall numpy sklearn ,看看是否能解决问题。

If you installed via Homebrew: brew install --force numpy (there's no sklearn homebrew package) 如果通过Homebrew brew install --force numpybrew install --force numpy (没有sklearn homebrew软件包)

If you installed via MacPorts: 如果通过MacPorts安装:

port -f uninstall py27-numpy
port install py27-numpy

(But if you installed via either Homebrew or MacPorts, I recommend uninstalling ( port -f uninstall py27-numpy || brew uninstall numpy ) and installing via pip instead. (但是,如果您是通过Homebrew或MacPorts安装的,建议您卸载( port -f uninstall py27-numpy || brew uninstall numpy )并改为通过pip安装。

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

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