在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

    代表安装成功了。


    如果帮到你了,请赞赏支持:

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MachineLP

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值