准备工作:

  1. Pyton科学计算环境,推荐直接安装Anaconda选择Py2或者Py3版本都可以(注意选对版本,不要安装成32位的否则会出现“WindowsError:[Error 193] %1 不是有效的 Win32”错误)
    如果之前已经安装过了,请确定下你的版本:打开cmd,输入python,确定是64位的
  2. MinGW

    之后选择安装路径即可进行安装。
  3. Git Bash
    关于Git的安装基本选择默认选项即可

环境配置

  1. Python的相关环境变量Anaconda已经帮助我配置好
  2. 配置MinGW相关的环境变量:
    C:\Program Files\mingw-w64\x86_64-6.2.0-win32-seh-rt_v5-rev1-seh-rt_v5-rev1\mingw64\binC:\Program Files\mingw-w64\x86_64-6.2.0-win32-seh-rt_v5-rev1-seh-rt_v5-rev1\mingw64\x86_64-w64-mingw32\include添加到系统变量Path中。添加完毕后打开cmd,输入g++验证。下面的图片说明正确安装并配置。

下载xgboost

在所要安装的目录下打开Git Bash,依次输入如下命令

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update

编译xgboost

Windows

在xgboost目录内打开Git Bash窗口总依次输入:

cp make/mingw64.mk config.mk;
mingw32-make -j4;


最后运行结果如上,说明编译成功。

Ubuntu/Debian

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4

Linux GPU支持

$ mkdir build
$ cd build
$ cmake .. -DUSE_CUDA=ON
$ make -j

安装Python包

进入xgboost\python-package目录下,打开cmd运行 python setup.py install

如果在Python3版本下安装,可能会遇见如下错误

解决方案是将setup.py文件中的setup函数中大概在38行左右的include_package_data=False,改成True,然后重新执行安装命令。
安装好的提示

验证安装成功

打开python终端:输入 import xgboost as xgb 成功导入说明安装成功