scikit-learnをインストールする(win/marvericks)
scikit-learnとは
インストールしていくが・・・
サポート環境
公式ドキュメントにも書いてあるが、下記のようなライブラリが必要
- Python本体
- 依存ライブラリとか
Windows
Mac OS X (marvericks)
- Python本体はpyenvでいれた
- NumPy・SciPyはpipでインストールしていけばよい
pip install numpy
pip install scipy
- C/C++ compilerはxcode commandline toolをインストールすることでインストールされる
- marvericksから
xcode > open developer tool > more developer tool > commandline tool
- marvericksから
- scikit-learnをpipでインストールして終わり・・・のはずだった
pip install scikit-learn
gccのエラーと戦う
- このstackover flowや、このサイトで紹介されているように、marvericksのgccは何かおかしいらしい?
pip install scikit-learn
ってやると下記のようなエラーになったclang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future] clang: note: this will be a hard error (cannot be downgraded to a warning) in the future error: Command "c++ -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include -c sklearn/svm/src/libsvm/libsvm_template.cpp -o build/temp.macosx-10.9-intel-2.7/sklearn/svm/src/libsvm/libsvm_template.o" failed with exit status 1 ---------------------------------------- Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip_build_root/scikit-learn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-INtc9q-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/tmp/pip_build_root/scikit-learn Storing debug log for failure in /Users/xxxxx/Library/Logs/pip.log
stackover flowにあったように、エラーを無視するオプションをつけて実行すると動くようになった
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install scikit-learn
上のコマンドを実行するとコンソールにはこんな感じで表示された(一部抜粋)
ものすごいエラーっぽい
sklearn/linear_model/sgd_fast.c:13885:49: warning: unused function '__Pyx_c_sum' [-Wunused-function] static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) { ^ sklearn/linear_model/sgd_fast.c:13891:49: warning: unused function '__Pyx_c_diff' [-Wunused-function] static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) { ^
けど、コンソール出力がエラーっぽいけど、インストールは成功する!!
- 上のワーニングがでている時に、途中で処理を中止していたので、成功するということに2時間ぐらい気がつけなかった
くっそ!!
Partial import of sklearn during the build process. Successfully installed scikit-learn Cleaning up...
ワーニングでてるのに、ちゃんと成功しているのかめっちゃ不安なので、動かしてみる
- importしてみたけど、エラーはでなかった
機械学習は動かしてないけど、importできたってことは動くよね。。。?
Python 3.3.3 (default, Mar 19 2014, 01:44:51) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> digits = datasets.load_digits() >>> digits.target array([0, 1, 2, ..., 8, 9, 8])
- importしてみたけど、エラーはでなかった