kuroの覚え書き

96の個人的覚え書き

xgboostのインストール

前回xgboostのインストールがすんなりいかなくて色々回り道をしたが、ちゃんとエラーの内容を紐解けば正しいやり方がわかったろうに、ということでやり直し。

まず、一旦戻ってpip3のところから。

$ pip3 list
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Package            Version    
------------------ -----------
abifpy             0.9        
alembic            0.9.5

・・・

WARNING: You are using pip version 20.0.2; however, version 20.1 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -m pip install --upgrade pip' command.

ここでまずひとつわかることはpipの使い方が

$ pip3 list

というやり方から

$ python3 -m pip list

というやり方に今後は変えますよ、ということ。

あとpipのバージョンが古そうなので

$ python3 -m pip install --upgrade pip

で早速バージョンアップ。

tensorflow==1.14
keras
は正常にインストールできて

$ python3 -m pip install xgboost
Defaulting to user installation because normal site-packages is not writeable
Collecting xgboost
  Downloading xgboost-1.0.2.tar.gz (821 kB)
     |████████████████████████████████| 821 kB 3.8 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/setup.py'"'"'; __file__='"'"'/private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-pip-egg-info-f1lsy3uh
         cwd: /private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/
    Complete output (27 lines):
    ++ pwd
    + oldpath=/private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost
    + cd ./xgboost/
    + mkdir -p build
    + cd build
    + cmake ..
    ./xgboost/build-python.sh: line 21: cmake: command not found
    + echo -----------------------------
    -----------------------------
    + echo 'Building multi-thread xgboost failed'
    Building multi-thread xgboost failed
    + echo 'Start to build single-thread xgboost'
    Start to build single-thread xgboost
    + cmake .. -DUSE_OPENMP=0
    ./xgboost/build-python.sh: line 27: cmake: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/setup.py", line 42, in <module>
        LIB_PATH = libpath['find_lib_path']()
      File "/private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/xgboost/libpath.py", line 50, in find_lib_path
        'List of candidates:\n' + ('\n'.join(dll_path)))
    XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
    List of candidates:
    /private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/xgboost/libxgboost.dylib
    /private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/xgboost/../../lib/libxgboost.dylib
    /private/var/folders/sf/3lk5x37135586w0jgqyjq_yc0000gn/T/pip-install-c294olba/xgboost/xgboost/./lib/libxgboost.dylib
    /Library/Frameworks/Python.framework/Versions/3.6/xgboost/libxgboost.dylib
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

やはりこうなる。

./xgboost/build-python.sh: line 21: cmake: command not found

ここでわかることはcmakeがないよ、ってこと。
なのでcmakeをインストールしてやろうとすると

$ brew install cmake
Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
  sudo chown -R $(whoami) /usr/local/Cellar
Error: The following directories are not writable by your user:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/share

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/Cellar /usr/local/Homebrew /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share

brewがコケる。

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: The following directories are not writable by your user:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/share

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/Cellar /usr/local/Homebrew /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share

Warning: The following directories do not exist:
/usr/local/sbin

You should create these directories and change their ownership to your account.
  sudo mkdir -p /usr/local/sbin
  sudo chown -R $(whoami) /usr/local/sbin

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
  /Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
  /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
  /Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
  /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
  /Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
  /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config

Warning: Putting non-prefixed coreutils in your path can cause gmp builds to fail.

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
  /usr/local/lib/libtcl8.6.dylib
  /usr/local/lib/libtk8.6.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

・・・

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .pc files:
  /usr/local/lib/pkgconfig/tcl.pc
  /usr/local/lib/pkgconfig/tk.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
  /usr/local/lib/libtclstub8.6.a
  /usr/local/lib/libtkstub8.6.a

Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  texi2html

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:
  smtpd2.7.py
  idle2.7
  idle
  ctags
  git-receive-pack
  texi2pdf
  2to3-2.7
  etags
  easy_install
  pydoc
  python
  pythonw
  python2.7-config
  pydoc2.7
  git-upload-archive
  pythonw2.7
  emacs
  emacsclient
  texindex
  python-config
  info
  easy_install-2.7
  texi2dvi
  python2.7
  git-cvsserver
  infokey
  git-shell
  git-upload-pack
  smtpd.py
  git
  makeinfo
  install-info

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
  echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Warning: Your Xcode (8.2.1) is too outdated.
Please update to Xcode 10.1 (or delete it).
Xcode can be updated from the App Store.


Warning: Your Xcode (8.2.1) is outdated.
Please update to Xcode 10.1 (or delete it).
Xcode can be updated from the App Store.


Warning: Broken symlinks were found. Remove them with `brew prune`:
  /usr/local/bin/ctags
  /usr/local/bin/ebrowse
  /usr/local/bin/emacs
  /usr/local/bin/emacsclient
  /usr/local/bin/etags
Warning: Use hdf5 instead of deprecated homebrew/science/hdf5
Warning: Use htslib instead of deprecated homebrew/science/htslib
Warning: Use bowtie2 instead of deprecated homebrew/science/bowtie2

とまあ盛大にWarningが出る。
この中の、最初のWarningの対処を言われたとおりにやる。

$ sudo chown -R $(whoami) /usr/local/Cellar /usr/local/Homebrew /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share
Password:

するとbrew installがちゃんと使えるようになった。

$ brew install cmake
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3.mavericks.bottle.tar.gz
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (or will be during this `brew` run).

==> Auto-updated Homebrew!
Updated 4 taps (homebrew/core, homebrew/cask, brewsci/bio and brewsci/science).
==> New Formulae

・・・

==> Downloading https://homebrew.bintray.com/bottles/cmake-3.17.2.mojave.bottle.
==> Downloading from https://akamai.bintray.com/ed/edc5ec271841a8b8558f8d60ef510
######################################################################## 100.0%
==> Pouring cmake-3.17.2.mojave.bottle.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/cmake
==> Summary
🍺  /usr/local/Cellar/cmake/3.17.2: 6,156 files, 58.1MB

ここまでやってやると

$ python3 -m pip install xgboost
Defaulting to user installation because normal site-packages is not writeable
Collecting xgboost
  Using cached xgboost-1.0.2.tar.gz (821 kB)
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost) (1.16.1)
Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost) (0.19.1)
Building wheels for collected packages: xgboost
  Building wheel for xgboost (setup.py) ... done
  Created wheel for xgboost: filename=xgboost-1.0.2-cp36-cp36m-macosx_10_14_intel.whl size=3381969 sha256=f8ef36fabe464c9b019fe99671876efa3350dd3c4f275cb5a9b04f717eb0e6d9
  Stored in directory: /Users/kkuro/Library/Caches/pip/wheels/06/0a/03/1dd5317e4ad7882450a41265354839831f7094739ee401043c
Successfully built xgboost
Installing collected packages: xgboost
Successfully installed xgboost-1.0.2

このようにエラーなく、スッキリインストールが完了した。
gccのバージョンアップは不要だったわけだ。