Pip install xgboost on Mac OS X (python36)

运行环境

Mac OS 10.12.6
python 3.6.2
pip 9.0.1
gcc 7.2.0

问题

无法使用pip install xgboost安装xgboost

$pip install xgboost
Collecting xgboost
Using cached xgboost-0.6a2.tar.gz
Complete output from command python setup.py egg_info:
rm -f -rf build build_plugin lib bin ~ /~ //~ ///~ /.o //.o ///.o xgboost
which: no gcc-5 in (/Users/yong.zhang/entity-embedding-rossmann/venv/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/Users/yong.zhang/anaconda3/bin:/Users/yong.zhang/Applications/anaconda/bin :/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/Cellar/hadoop/2.8.1/libexec/sbin:/usr/local/Cellar/hadoop/2.8.1/libexec/bin)
...
make: *** [build/learner.o] Error 127
make: *** Waiting for unfinished jobs....
clang-omp++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/logging.o src/logging.cc >build/logging.d
/bin/sh: clang-omp++: command not found
make: *** [build/logging.o] Error 127
-----------------------------
Building multi-thread xgboost failed
Start to build single-thread xgboost
rm -f -rf build build_plugin lib bin ~ /~ //~ //
/~ /.o //.o ///.o xgboost
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/x6/82p0vbnx3kj9ffcvr35y_tr40000gp/T/pip-build-jl7jcggp/xgboost/setup.py", line 29, in
LIB_PATH = libpath'find_lib_path'
File "/private/var/folders/x6/82p0vbnx3kj9ffcvr35y_tr40000gp/T/pip-build-jl7jcggp/xgboost/xgboost/libpath.py", line 45, in find_lib_path
'List of candidates:\n' + ('\n'.join(dll_path)))
XGBoostLibraryNotFound: Cannot find XGBoost Libarary in the candicate path, did you install compilers and run build.sh in root path?
List of candidates:
/private/var/folders/x6/82p0vbnx3kj9ffcvr35y_tr40000gp/T/pip-build-jl7jcggp/xgboost/xgboost/libxgboost.so
/private/var/folders/x6/82p0vbnx3kj9ffcvr35y_tr40000gp/T/pip-build-jl7jcggp/xgboost/xgboost/../../lib/libxgboost.so
/private/var/folders/x6/82p0vbnx3kj9ffcvr35y_tr40000gp/T/pip-build-jl7jcggp/xgboost/xgboost/./lib/libxgboost.so

出错原因

pip上的xgboost当前只支持gcc5, 而Mac OS X大多数gcc都已经是gcc6以上的版本,比如我的是gcc7

解决办法

感谢github,基友总是在需要的时候出现,
参考Problems while installing in OSX 10.11.6? #1501, 找到解决办法

$ brew install gcc@5
$ pip install xgboost

这是最简洁的解决办法,当然也可以install from source,此处不做介绍。

上面的办法应该可以解决大多数人的问题,但是我还遇到一点小麻烦。brew install gcc@5时发现下面的问题

Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man7/fsf-funding-5.7
/usr/local/share/man/man7 is not writable.

此处涉及brew permission的问题,寻找Brew Troubleshooting解决

If commands fail with permissions errors, check the permissions of /usr/local’s subdirectories. If you’re unsure what to do, you can run cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var Frameworks.

你可能感兴趣的:(Pip install xgboost on Mac OS X (python36))