美文网首页python/flask
在mac上安装Xgboost Python库

在mac上安装Xgboost Python库

作者: Detailscool | 来源:发表于2017-04-10 16:36 被阅读3964次

    最近在mac上用到xgboost库,安装时遇到颇多大坑,网上查了很多答案几乎都是win上的问题,没遇到理想的,自己也就摸着石头把几个大坑给填了,总结一下,给后人少走点弯路。

    1.错误

    倘若直接 pip install xgboost时,会出现Command "python setup.py egg_info" failed with error code 1的错误提示,
    还是乖乖使用Github源代码安装吧~

    2.正确的打开方式

    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包则不会

    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包的原因

      那我就跑吧
    cd ~/xgboost
    bash build.sh
    

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

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

    cd python-package; sudo python setup.py install
    

    最后会终端出现:

    Finished processing dependencies for xgboost==0.6
    

    代表安装成功了。

    3.打开Pycharm

    安装成功后Pycharm里 —> Preferences —> Project Interpreter 就可以找到xgboost的影子了

    Pycharm —> Preferences —> Project Interpreter

    相关文章

      网友评论

        本文标题:在mac上安装Xgboost Python库

        本文链接:https://www.haomeiwen.com/subject/owgsattx.html