Mac OS X でのインストール方法#
pipを利用して簡単インストール.
pip install scikit-learn
インストールは完了.しかし,実際にインポートしようとすると以下のようなエラーが出力.
> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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
ここを参照に解決を試みるも,うまくいかない.numpyのバージョンが合っていないようだったので,下のコードでインポートのパスを調べ,関連のディレクトリを削除後,再度numpyをインストールしたところ,無事インポートすることができた.
import numpy
print numpy.__file__ #importするファイルのパスを表示
追記
pip install したパッケージをimport できないときの対応でも類似の事象が報告されていました.結局pipがインストールしたパスと,pythonがインポートの際に見に行くパスが違うことが原因っぽいですね.