1. 程式人生 > >在mac上安裝Xgboost Python庫

在mac上安裝Xgboost Python庫

最近在mac上用到xgboost庫,安裝時遇到頗多大坑,網上查了很多答案几乎都是win上的問題,沒遇到理想的,自己也就摸著石頭把幾個大坑給填了,總結一下,給後人少走點彎路。

1.錯誤

倘若直接 pip install xgboost時,會出現Command "python setup.py egg_info" failed with error code 1的錯誤提示,
還是乖乖使用Github原始碼安裝吧~

2.正確的開啟方式

  • 1.
    cd ~
    git clone --recursive https://github.com/dmlc/xgboost
    終端輸出:
    Cloning into 'xgboost'
    ... remote: Counting objects: 19864, done. remote: Total 19864 (delta 0), reused 0 (delta 0), pack-reused 19863 Receiving objects: 100% (19864/19864), 6.69 MiB | 76.00 KiB/s, done. Resolving deltas: 100% (11937/11937), done. Submodule 'dmlc-core' (https://github.com/dmlc/dmlc-core) registered for path 'dmlc-core' Submodule 'rabit'
    (https://github.com/dmlc/rabit) registered for path 'rabit' Cloning into '/Users/henrylee/xgboost/dmlc-core'... Cloning into '/Users/henrylee/xgboost/rabit'... Submodule path 'dmlc-core': checked out 'b5bec5481df86e8e6728d8bd80a61d87ef3b2cd5' Submodule path 'rabit': checked out 'a764d45cfb438cc9f15cf47ce586c02ff2c65d0f'

可看出gitclone下來的時候回自動clone上其引用庫,而直接使用Release包則不會

  • 2.
    cd xgboost
    注意: 倘若直接使用
    cd python-package; sudo python setup.py install
    會出現:
    Traceback (most recent call last):
    File "setup.py", line 19, in <module>
    LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
    File "xgboost/libpath.py", line 46, in find_lib_path
    'List of candidates:\n' + ('\n'.join(dll_path)))
    __builtin__.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
    的錯誤提示,意思是你還是先跑跑資料夾下面的build.sh吧
    注:
    使用Release包會報錯/dmlc-core下找不到某檔案,這也是不要使用Release包的原因
  • 3.
    那我就跑吧

    cd ~/xgboost
    bash build.sh

    這時會出現一大堆C++編譯,若無出現則可能像官網所說使用brew安裝下GCC——brew install gcc --without-multilib

  • 4.
    這個時候就真可以名正而順地使用

    cd python-package; sudo python setup.py install

    最後會終端出現:

    Finished processing dependencies for xgboost==0.6

    代表安裝成功了。


    如果幫到你了,請讚賞支援: