2016-08-21 4 views
0

これまでに同様の問題を抱えていた人がいらっしゃいましたか? Mac OSXでのPython 2.7の使用再インストールしようとしたときPython 2.7のnumpy問題 - numpy.dtypeのサイズが間違っています

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 

編集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. 
+1

あなたのコードは私のために働きますsklearnを再インストールする必要があるかもしれません – James

+0

Thanks @James、なぜsklearnと関係がありますか? 'numpy'に関連していますか? –

+1

OSErrorを取り除くにはhttp://stackoverflow.com/questions/15028648/is-it-acceptable-safe-to-run-pip-install-under-sudoを見てください。しかし、私がミニコンダをインストールし、別のpython環境をインストールすると – atomsmasher

答えて

2

に会いました。

sudo pip install --upgrade --force-reinstall numpy sklearnを実行して、そのトリックがあるかどうかを確認してください。

あなたが自作経由でインストールした場合:brew install --force numpy(ないsklearn自作パッケージはありません)

あなたはMacPortsの経由でインストールした場合:

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

(しかし、あなたが自作やMacPortsのいずれかを経由してインストールした場合、私は(アンインストールをお勧めしますport -f uninstall py27-numpy || brew uninstall numpy)、代わりにpip経由でインストールしてください

+0

クリスチャン、私はHomebrewもMacPortsも使用していません。OSXのネイティブPythonフレームワークを使用してください。私はあなたのコマンドを試してさらに奇妙な問題を遭遇しました。編集して1部に投稿しました。見ていただければ幸いです。 :) –

関連する問題