最近在mac上用到xgboost庫(kù),安裝時(shí)遇到頗多大坑赠橙,網(wǎng)上查了很多答案幾乎都是win上的問(wèn)題耽装,沒(méi)遇到理想的,自己也就摸著石頭把幾個(gè)大坑給填了期揪,總結(jié)一下掉奄,給后人少走點(diǎn)彎路。
1.錯(cuò)誤
倘若直接 pip install xgboost
時(shí)凤薛,會(huì)出現(xiàn)Command "python setup.py egg_info" failed with error code 1
的錯(cuò)誤提示姓建,
還是乖乖使用Github源代碼安裝吧~
2.正確的打開(kāi)方式
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下來(lái)的時(shí)候回自動(dòng)clone上其引用庫(kù),而直接使用Release包則不會(huì)
cd xgboost
注意: 倘若直接使用
cd python-package; sudo python setup.py install
會(huì)出現(xiàn):
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?
的錯(cuò)誤提示缤苫,意思是你還是先跑跑文件夾下面的build.sh吧
注:
使用Release包會(huì)報(bào)錯(cuò)/dmlc-core下找不到某文件速兔,這也是不要使用Release包的原因
cd ~/xgboost
bash build.sh
這時(shí)會(huì)出現(xiàn)一大堆C++編譯,若無(wú)出現(xiàn)則可能像官網(wǎng)所說(shuō)使用brew安裝下GCC——brew install gcc --without-multilib
這個(gè)時(shí)候就真可以名正而順地使用
cd python-package; sudo python setup.py install
最后會(huì)終端出現(xiàn):
Finished processing dependencies for xgboost==0.6
代表安裝成功了活玲。
3.打開(kāi)Pycharm
安裝成功后Pycharm里 —> Preferences —> Project Interpreter 就可以找到xgboost的影子了