katsuyukikun’s diary

とある天パーエンジニアのblog

python3.7(pip3)でscikit-learnをインストールしようとしたらエラった話

mac初期化して、綺麗さっぱり!

もう一度環境設定し直そうと思って機械学習系のライブラリ入れてたらなんかエラーになったのでログとして残しておこうかなと思います。

 

エラー内容

どういう動作をしていたかは以下です。

  • homebrewでpython3をインストール
  • pipでscikit-learnをインストトール
$ brew update # brewをインストールしていたので最新にした
$ brew doctor # 問題ないか確認
Your system is ready to brew.
$
$ pip3 install scikit-learn # scikit-learnをインストール
・・・エラー出る

エラー内容はこちら *長すぎるので一部省略

Collecting scikit-learn
  Downloading https://files.pythonhosted.org/packages/f5/2c/5edf2488897cad4fb8c4ace86369833552615bf264460ae4ef6e1f258982/scikit-learn-0.19.1.tar.gz (9.5MB)
    100% |████████████████████████████████| 9.5MB 2.4MB/s 
Building wheels for collected packages: scikit-learn
  Running setup.py bdist_wheel for scikit-learn ... error
  Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-install-73hi3d9o/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-wheel-9kivc9ej --python-tag cp37:
  Partial import of sklearn during the build process.
  blas_opt_info:
  blas_mkl_info:

  customize UnixCCompiler
    libraries mkl_rt not found in ['/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE
  
  blis_info:
  customize UnixCCompiler
    libraries blis not found in ['/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib', '/usr/local/lib', '/usr/lib']
    NOT AVAILABLE
  
  ・略(customize UnixCCompilerのNOT AVAILABLE系のエラーが続く)
  ・
  ・
  
    FOUND:
      extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
      extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
      define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]
  
  running bdist_wheel

  ・略(色々buildしたりcopyしたりしたログが出力されていました)
  ・
  ・
  running build_clib
  customize UnixCCompiler
  #### ['clang', '-Wno-unused-result', '-Wsign-compare', '-Wunreachable-code', '-fno-common', '-dynamic', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall'] #######
  customize UnixCCompiler using build_clib

  ・略(色々buildしたりcopyしたりしたログが出力されていました)
  ・
  ・
  /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
  #warning "Using deprecated NumPy API, disable it by " \
   ^
  sklearn/cluster/_dbscan_inner.cpp:5960:21: error: no member named 'exc_type' in '_ts'
      *type = tstate->exc_type;
              ~~~~~~  ^
  sklearn/cluster/_dbscan_inner.cpp:5961:22: error: no member named 'exc_value' in '_ts'; did you mean 'curexc_value'?
      *value = tstate->exc_value;
                       ^~~~~~~~~
                       curexc_value

  ・略(error: no member named などのエラーが続く)
  ・
  ・

  sklearn/cluster/_dbscan_inner.cpp:6034:13: error: no member named 'exc_traceback' in '_ts'; did you mean 'curexc_traceback'?
      tstate->exc_traceback = local_tb;
              ^~~~~~~~~~~~~
              curexc_traceback
  /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
      PyObject *curexc_traceback;
                ^
  1 warning and 15 errors generated.
  In file included from sklearn/cluster/_dbscan_inner.cpp:514:
  In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
  In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
  In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1816:
  /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
  #warning "Using deprecated NumPy API, disable it by " \
   ^
  sklearn/cluster/_dbscan_inner.cpp:5960:21: error: no member named 'exc_type' in '_ts'
      *type = tstate->exc_type;
              ~~~~~~  ^
  sklearn/cluster/_dbscan_inner.cpp:5961:22: error: no member named 'exc_value' in '_ts'; did you mean 'curexc_value'?
      *value = tstate->exc_value;
                       ^~~~~~~~~
                       curexc_value

  ・略(error: no member named などのエラーが続く)
  ・
  ・

  /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
      PyObject *curexc_traceback;
                ^
  1 warning and 15 errors generated.
  error: Command "clang++ -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c sklearn/cluster/_dbscan_inner.cpp -o build/temp.macosx-10.13-x86_64-3.7/sklearn/cluster/_dbscan_inner.o -MMD -MF build/temp.macosx-10.13-x86_64-3.7/sklearn/cluster/_dbscan_inner.o.d" failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for scikit-learn
  Running setup.py clean for scikit-learn
Failed to build scikit-learn
Installing collected packages: scikit-learn
  Running setup.py install for scikit-learn ... error
    Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-install-73hi3d9o/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-record-wgjf7j3u/install-record.txt --single-version-externally-managed --compile:
    Partial import of sklearn during the build process.
    blas_opt_info:
    blas_mkl_info:
    customize UnixCCompiler
      libraries mkl_rt not found in ['/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib', '/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
    blis_info:
    customize UnixCCompiler
      libraries blis not found in ['/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib', '/usr/local/lib', '/usr/lib']
      NOT AVAILABLE
    
  ・略(customize UnixCCompilerのNOT AVAILABLE系のエラーが続く)
  ・
  ・
    
      FOUND:
        extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
        extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
        define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]
    
    running install
    running build
  ・略(色々buildしたりcopyしたりしたログが出力されていました)
  ・
  ・
    customize UnixCCompiler
    #### ['clang', '-Wno-unused-result', '-Wsign-compare', '-Wunreachable-code', '-fno-common', '-dynamic', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall'] #######
    customize UnixCCompiler using build_clib
    building 'libsvm-skl' library
    compiling C++ sources
    C compiler: clang++ -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall
    
    creating build/temp.macosx-10.13-x86_64-3.7
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn/svm
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn/svm/src
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn/svm/src/libsvm
    compile options: '-I/usr/local/lib/python3.7/site-packages/numpy/core/include -c'
    clang++: sklearn/svm/src/libsvm/libsvm_template.cpp
    ar: adding 1 object files to build/temp.macosx-10.13-x86_64-3.7/liblibsvm-skl.a
    ranlib:@ build/temp.macosx-10.13-x86_64-3.7/liblibsvm-skl.a
    running build_ext
    customize UnixCCompiler
    customize UnixCCompiler using build_ext
    customize UnixCCompiler
    #### ['clang', '-Wno-unused-result', '-Wsign-compare', '-Wunreachable-code', '-fno-common', '-dynamic', '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall'] #######
    customize UnixCCompiler using build_ext
    building 'sklearn.__check_build._check_build' extension
    compiling C sources
    C compiler: clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall
    
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn/__check_build
    compile options: '-I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c'
    clang: sklearn/__check_build/_check_build.c
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-3.7/sklearn/__check_build/_check_build.o -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -Lbuild/temp.macosx-10.13-x86_64-3.7 -o build/lib.macosx-10.13-x86_64-3.7/sklearn/__check_build/_check_build.cpython-37m-darwin.so
    building 'sklearn.cluster._dbscan_inner' extension
    compiling C++ sources
    C compiler: clang++ -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall
    
    creating build/temp.macosx-10.13-x86_64-3.7/sklearn/cluster
    compile options: '-I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c'
    clang++: sklearn/cluster/_dbscan_inner.cpp
    In file included from sklearn/cluster/_dbscan_inner.cpp:514:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1816:
    /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
    #warning "Using deprecated NumPy API, disable it by " \
     ^
    sklearn/cluster/_dbscan_inner.cpp:5960:21: error: no member named 'exc_type' in '_ts'
        *type = tstate->exc_type;
                ~~~~~~  ^
    sklearn/cluster/_dbscan_inner.cpp:5961:22: error: no member named 'exc_value' in '_ts'; did you mean 'curexc_value'?
        *value = tstate->exc_value;
                         ^~~~~~~~~
                         curexc_value
  ・略(error: no member named などのエラーが続く)
  ・
  ・
    /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
        PyObject *curexc_traceback;
                  ^
    1 warning and 15 errors generated.
    In file included from sklearn/cluster/_dbscan_inner.cpp:514:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/arrayobject.h:4:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18:
    In file included from /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1816:
    /usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: "Using deprecated NumPy API, disable it by "          "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
    #warning "Using deprecated NumPy API, disable it by " \
     ^
    sklearn/cluster/_dbscan_inner.cpp:5960:21: error: no member named 'exc_type' in '_ts'
        *type = tstate->exc_type;
                ~~~~~~  ^
    sklearn/cluster/_dbscan_inner.cpp:5961:22: error: no member named 'exc_value' in '_ts'; did you mean 'curexc_value'?
        *value = tstate->exc_value;
                         ^~~~~~~~~
                         curexc_value
  ・略(error: no member named などのエラーが続く)
  ・
  ・
    /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pystate.h:238:15: note: 'curexc_traceback' declared here
        PyObject *curexc_traceback;
                  ^
    1 warning and 15 errors generated.
    error: Command "clang++ -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c sklearn/cluster/_dbscan_inner.cpp -o build/temp.macosx-10.13-x86_64-3.7/sklearn/cluster/_dbscan_inner.o -MMD -MF build/temp.macosx-10.13-x86_64-3.7/sklearn/cluster/_dbscan_inner.o.d" failed with exit status 1
    
    ----------------------------------------
Command "/usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-install-73hi3d9o/scikit-learn/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-record-wgjf7j3u/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/0f/7pybjfq55vx60gjyjwbx4k0c0000gn/T/pip-install-73hi3d9o/scikit-learn/

対処方法

調べてみたところ一昨日くらいに修正されマージされていたみたい。 なので最新のをインストールすれば良い。 brewに反映されるまで1ヶ月くらいかかるということなので、(8月には治っているかな?)それまでpythonのバージョンを下げれば インストールできるよとのこと!(本当かどうかは試していないのでわかりませんが・・)

Note that you would need Cython >=0.27.3 to compile it..

ということなのでCythonをインストールしてからdevの最新を入れたら通りました!

$ pip3 install Cython
$ pip3 install https://github.com/scikit-learn/scikit-learn/archive/master.zip
Successfully built scikit-learn
Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.20.dev0
$