Contents
  1. 1. 错误
  2. 2. 正确的打开方式
    1. 2.1. Step 1
    2. 2.2. Step 2
    3. 2.3. Step 3
    4. 2.4. Step 4

最近在Mac上用到XGboost库,安装时遇到颇多大坑,网上查了很多答案几乎都是win上的问题。

错误

倘若直接 pip install xgboost 时,会出现如下错误提示

1
Command "python setup.py egg_info" failed with error code 1

还是乖乖使用Github源代码安装吧~

正确的打开方式

Step 1

1
2
cd ~ //mac 通常选默认的home路径
git clone --recursive https://github.com/dmlc/xgboost

终端输出:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Cloning into 'xgboost'...
remote: Counting objects: 20916, done.
remote: Total 20916 (delta 0), reused 0 (delta 0), pack-reused 20916
Receiving objects: 100% (20916/20916), 7.27 MiB | 290.00 KiB/s, done.
Resolving deltas: 100% (12438/12438), done.
Submodule 'cub' (https://github.com/NVlabs/cub) registered for path 'cub'
Submodule 'dmlc-core' (https://github.com/dmlc/dmlc-core) registered for path 'dmlc-core'
Submodule 'nccl' (https://github.com/dmlc/nccl) registered for path 'nccl'
Submodule 'rabit' (https://github.com/dmlc/rabit) registered for path 'rabit'
...
remote: Total 3142 (delta 0), reused 0 (delta 0), pack-reused 3142
Receiving objects: 100% (3142/3142), 899.95 KiB | 148.00 KiB/s, done.
Resolving deltas: 100% (2040/2040), done.
Submodule path 'cub': checked out 'f3937a96fdec78a73446aaaa114c112ff31f5503'
Submodule path 'dmlc-core': checked out 'b5bec5481df86e8e6728d8bd80a61d87ef3b2cd5'
Submodule path 'nccl': checked out '018ff75f78e4d3616051fdcd3da7cf64249b6d59'
Submodule path 'rabit': checked out 'a764d45cfb438cc9f15cf47ce586c02ff2c65d0f'

可看出gitclone下来的时候回自动clone上其引用库,而直接使用Release包则不会

Step 2

1
cd xgboost

注意: 倘若直接使用

1
cd python-package; sudo python setup.py install

会出现如下的错误提示:

1
2
3
4
5
6
7
8
9
10
11
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 49, 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?
List of candidates:
/Users/fengyening/xgboost/python-package/xgboost/libxgboost.dylib
/Users/fengyening/xgboost/python-package/xgboost/../../lib/libxgboost.dylib
/Users/fengyening/xgboost/python-package/xgboost/./lib/libxgboost.dylib
/Library/Frameworks/Python.framework/Versions/2.7/xgboost/libxgboost.dylib

还是先跑跑文件夹下面的build.sh吧

使用Release包会报错/dmlc-core下找不到某文件,这也是不要使用Release包的原因:
那我就跑吧

Step 3

1
2
cd ~/xgboost
bash build.sh

这时会出现一大堆C++编译,若无出现则可能像官网所说使用brew安装下GCC

1
——brew install gcc --without-multilib

Step 4

这个时候就真可以名正而顺地使用

1
cd python-package; sudo python setup.py install

最后会终端出现:

1
Finished processing dependencies for xgboost==0.6
Contents
  1. 1. 错误
  2. 2. 正确的打开方式
    1. 2.1. Step 1
    2. 2.2. Step 2
    3. 2.3. Step 3
    4. 2.4. Step 4