在Windows10 64位 Anaconda4 Python3.5下安装XGBoost

系统环境:

Windows10 64bit Anaconda4 Python3.5.1 

软件安装:

  • Git for Windows 
  • MINGW
    • 在安装的时候要改一个选择(Architecture选择x86_64,其他不变)

安装步骤:

  1. 拷贝源文件并且编译
    1. 在你想要存源码的路径文件夹里使用 Git Bash
    2. 也可以直接使用命令:
      $ cd /d/XGBoost/
    3. 克隆源码并初始化更新:
      $ git clone --recursive https://github.com/dmlc/xgboost
      $ cd xgboost
      $ git submodule init
      $ git submodule update
  2. 将Git(Gitcmd)和MINGW(C:Program Filesmingw-w64x86_64-5.3.0-posix-seh-rt_v4-rev0mingw64in)添加到系统环境变量PATH中:
    1. 关掉Git Bash终端并重新打开,检查环境变量是否添加好了
      $ which mingw32-make

      正常的返回结果应该是这样:

      /c/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/bin/mingw32-make

      为了方便,我们更改一下名称:

      $ alias make='mingw32-make'
  3. 开始build XGBoost
    1. 在xgboost路径下
       $ cd /c/XGBoost/xgboost
    2. 一次运行以下的所有的代码
      $ cd dmlc-core
      $ make -j4
      $ cd ../rabit
      $ make lib/librabit_empty.a -j4
      $ cd ..
      $ cp make/mingw64.mk config.mk
      $ make -j4
    3. 等最后一行命令运行完就build完成了。
  4. 安装Python安装包模块
    1. 首先cd到python-package路径【这一步在终端命令行执行】
      cd d:XGBoostxgboostpython-package
    2. 然后安装Python包:【这一步在终端命令行执行】
      d:XGBoostxgboostpython-package>python setup.py install
    3. 安装完成之后直接导入xgboost会报错,所以还要添加g++运行库到环境路径变量:【这一步在ipython中执行】
      import os
      
      mingw_path = 'C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin'
      
      os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']

      这一步完成之后所有的安装就都完成了,可以正常导入使用了。祝大家生活愉快!

原文地址:https://www.cnblogs.com/cutd/p/5497929.html