1.首先下载mingw:
https://sourceforge.net/projects/mingw-w64/postdownload?source=dlp 安装时选择64位 其余不变
2.下载xgboost
https://github.com/dmlc/xgboost/releases
3.安装xgboost
在你想要存源码的路径文件夹里使用 Git Bash
也可以直接使用命令:
$ cd /d/XGBoost/
克隆源码并初始化更新:
$ git clone --recursive https://github.com/dmlc/xgboost
$ cd xgboost
$ git submodule init
$ git submodule update
将Git(Git\cmd)和MINGW(C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin)添加到系统环境变量PATH中:
关掉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'
开始build XGBoost
在xgboost路径下
$ cd /c/XGBoost/xgboost
一次运行以下的所有的代码
$ cd dmlc-core
$ make -j4
$ cd ../rabit
$ make lib/librabit_empty.a -j4
$ cd ..
$ cp make/mingw64.mk config.mk
$ make -j4
等最后一行命令运行完就build完成了。
安装Python安装包模块
首先cd到python-package路径【这一步在终端命令行执行】
cd d:\XGBoost\xgboost\python-package
然后安装Python包:【这一步在终端命令行执行】
d:\XGBoost\xgboost\python-package>python setup.py install
安装完成之后直接导入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']
这一步完成之后所有的安装就都完成了,可以正常导入使用了。祝大家生活愉快!