在mac上安装Xgboost Python库

来源:互联网 发布:美国博士申请条件 知乎 编辑:程序博客网 时间:2024/05/21 11:03

最近在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
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