如何在macOS上安装xgboost?

时间:2019-08-13 18:29:08

标签: python xgboost

我正在使用macOS Mojave(编辑:使用python3,crew-llvm默认通过brew安装)。我试图用不同的方法来安装xgboost都没有用。我正在伸出手来使它工作。

首先,我只是尝试了pip install xgboost。这给出了下面列出的一长条错误消息。

   ERROR: Command errored out with exit status 1:
     command: /Users/schiefer/Documents/Code/ml/notebooks/venv2/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/setup.py'"'"'; __file__='"'"'/private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/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 pip-egg-info
         cwd: /private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/
    Complete output (139 lines):
    ++ pwd
    + oldpath=/private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost
    + cd ./xgboost/
    + echo darwin18
    + grep -q darwin
    + LIB_XGBOOST=libxgboost.dylib
    + which g++-5
    + which g++-7
    + which g++-8
    + which clang++
    /usr/local/opt/llvm/bin/clang++
    + export CC=clang
    + CC=clang
    + export CXX=clang++
    + CXX=clang++
    + make clean
    Makefile:31: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] - checked OK
    rm -f -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o #xgboost
    rm -f -rf build_tests *.gcov tests/cpp/xgboost_test
    if [ -d "R-package/src" ]; then \
            cd R-package/src; \
            rm -f -rf rabit src include dmlc-core amalgamation *.so *.dll; \
            cd /private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost; \
        fi
    + make lib/libxgboost.dylib -j4
    Makefile:31: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] - checked OK
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/logging.o src/logging.cc >build/logging.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/learner.o src/learner.cc >build/learner.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/c_api/c_api.o src/c_api/c_api.cc >build/c_api/c_api.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -fopenmp -MM -MT build/c_api/c_api_error.o src/c_api/c_api_error.cc >build/c_api/c_api_error.d
    In file included from src/c_api/c_api.cc:3:
    In file included from include/xgboost/data.h:10:
    dmlc-core/include/dmlc/base.h:190:10: fatal error: 'sys/types.h' file not found
    #include <sys/types.h>
             ^~~~~~~~~~~~~
    In file included from src/learner.cc:7:
    In file included from dmlc-core/include/dmlc/io.h:8:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/cstdio:100:
    /usr/local/opt/llvm/bin/../include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
    #include_next <stdio.h>
                  ^~~~~~~~~
    In file included from src/c_api/c_api_error.cc:6:
    In file included from dmlc-core/include/dmlc/thread_local.h:9:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/mutex:191:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/__mutex_base:15:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/chrono:798:
    /usr/local/opt/llvm/bin/../include/c++/v1/ctime:50:10: fatal error: 'time.h' file not found
    #include <time.h>
             ^~~~~~~~
    In file included from src/logging.cc:7:
    In file included from rabit/include/rabit/rabit.h:13:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/string:505:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/string_view:176:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/__string:57:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/algorithm:642:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/cstring:61:
    /usr/local/opt/llvm/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
    #include_next <string.h>
                  ^~~~~~~~~~
    1 error generated.
    make: *** [build/c_api/c_api_error.o] Error 1
    make: *** Waiting for unfinished jobs....
    1 error generated.
    1 error generated.
    make: *** [build/logging.o] Error 1
    1 error generated.
    make: *** [build/c_api/c_api.o] Error 1
    make: *** [build/learner.o] Error 1
    + 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
    + make clean
    Makefile:31: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] - checked OK
    rm -f -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o #xgboost
    rm -f -rf build_tests *.gcov tests/cpp/xgboost_test
    if [ -d "R-package/src" ]; then \
            cd R-package/src; \
            rm -f -rf rabit src include dmlc-core amalgamation *.so *.dll; \
            cd /private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost; \
        fi
    + make lib/libxgboost.dylib -j4 USE_OPENMP=0
    Makefile:31: MAKE [/Library/Developer/CommandLineTools/usr/bin/make] - checked OK
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -DDISABLE_OPENMP -MM -MT build/logging.o src/logging.cc >build/logging.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -DDISABLE_OPENMP -MM -MT build/learner.o src/learner.cc >build/learner.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -DDISABLE_OPENMP -MM -MT build/c_api/c_api_error.o src/c_api/c_api_error.cc >build/c_api/c_api_error.d
    clang++ -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude   -Idmlc-core/include -Irabit/include -I/include -O3 -funroll-loops -msse2 -fPIC -DDISABLE_OPENMP -MM -MT build/c_api/c_api.o src/c_api/c_api.cc >build/c_api/c_api.d
    In file included from src/learner.cc:7:
    In file included from dmlc-core/include/dmlc/io.h:8:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/cstdio:100:
    /usr/local/opt/llvm/bin/../include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
    In file included from src/c_api/c_api.cc:3:
    In file included from include/xgboost/data.h:10:
    dmlc-core/include/dmlc/base.h#include_next <stdio.h>
                  ^~~~~~~~~
    :190:10: fatal error: 'sys/types.h' file not found
    #include <sys/types.h>
             ^~~~~~~~~~~~~
    In file included from src/c_api/c_api_error.cc:6:
    In file included from dmlc-core/include/dmlc/thread_local.h:9:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/mutex:191:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/__mutex_base:15:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/chrono:798:
    /usr/local/opt/llvm/bin/../include/c++/v1/ctime:50:10: fatal error: 'time.h' file not found
    #include <time.h>
             ^~~~~~~~
    In file included from src/logging.cc:7:
    In file included from rabit/include/rabit/rabit.h:13:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/string:505:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/string_view:176:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/__string:57:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/algorithm:642:
    In file included from /usr/local/opt/llvm/bin/../include/c++/v1/cstring:61:
    /usr/local/opt/llvm/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
    #include_next <string.h>
                  ^~~~~~~~~~
    1 error generated.
    make: *** [build/c_api/c_api_error.o] Error 1
    make: *** Waiting for unfinished jobs....
    1 error generated.
    1 error generated.
    make: *** [build/c_api/c_api.o] Error 1
    make: *** [build/logging.o] Error 1
    1 error generated.
    make: *** [build/learner.o] Error 1
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/setup.py", line 42, in <module>
        LIB_PATH = libpath['find_lib_path']()
      File "/private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost/libpath.py", line 48, 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/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost/libxgboost.dylib
    /private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost/../../lib/libxgboost.dylib
    /private/var/folders/97/3q6wh2bs4lg_ckcfp_x0m2140000gn/T/pip-install-usgd8g0_/xgboost/xgboost/./lib/libxgboost.dylib
    /Users/schiefer/Documents/Code/ml/notebooks/venv2/bin/../xgboost/libxgboost.dylib
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我意识到我应该安装我所做的gcc(brew install gcc)。即使使用CC=gcc-9 CXX=g++-9 pip install xgboost指定c编译器,再次运行命令也会得到相同的结果。我无法链接gcc,因为我需要酿造的叮当声才能正常工作。

接下来,我尝试签出存储库,手动编译xgboost并安装python软件包。编译没有问题。但是,当我尝试转到xgboost/python-package并运行python setup.py develop --user时,出现以下错误块:

Install libxgboost from: ['../lib/libxgboost.dylib']
/Users/schiefer/Documents/Code/ml/notebooks/venv2/lib/python3.7/site-packages/setuptools/dist.py:481: UserWarning: The version specified ('1.0.0-SNAPSHOT') is an invalid version, this may not work as expected with newer versions of setuptools, pip, and PyPI. Please see PEP 440 for more details.
  "details." % self.metadata.version
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: option --user not recognized

因此,我尝试在虚拟环境中不使用--user选项。终于成功了,但这不是我真正追求的。

我可以采取什么步骤来使pip的安装正常进行?

4 个答案:

答案 0 :(得分:2)

当我在MacBook中安装XGboost时,我们遇到了相同的信息,我可以通过

重新安装cmake来解决此问题。
brew install cmake

答案 1 :(得分:1)

只有从源头开始的建筑才对我有用。

我在虚拟环境'p3'(python 3.7.1)中使用Apple clang版本11.0.0(clang-1100.0.33.8)在macOS Mojave 10.14.6上的步骤:

先决条件

$ brew install libomp

从源代码获取并构建最新版本

$ git clone --recursive https://github.com/dmlc/xgboost
$ cd xgboost
$ mkdir build
$ cd build
$ cmake ..
$ make -j4

切换到我的虚拟环境“ p3”

$ source ~/.virtualenvs/p3/bin/activate

将XGBoost安装为python软件包

(p3) $ cd ../python-package
(p3) $ pip install -e .

测试安装

(p3) $ python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
>>> xgboost.__version__
'1.1.0-SNAPSHOT'

答案 2 :(得分:0)

到目前为止,在macOS上安装XGBoost的最简单的方法是使用Anaconda路径:

conda install -c conda-forge xgboost

此命令还将解析诸如 libxgboost py-xgboost 之类的依赖项。

答案 3 :(得分:-1)

不幸的是,仅运行pip无效。您必须克隆git存储库,然后安装xgboost。

请参阅所附文章:

https://machinelearningmastery.com/install-xgboost-python-macos/