1.所需材料:
xgboost
xgboost 0.6 如果不想使用
git clone –recursive https://github.com/dmlc/xgboost 这个命令,嫌弃网速慢的同学,请移步 下载
如果想使用老版本 xgboost 0.47 请移步 下载
如果嫌本文讲的不仔细,请移步 xgboost官网
Anaconda3
下载地址
2.安装步骤
先确保机器上其他的Python环境都被卸载干净了
然后安装 Anaconda3,以免安装的时候报错。
先下载好xgboost 0.6的安装包,解压,打开cmd窗口,对了,貌似还有个git没下,请 移步
安装完git后,切换到解压目录。运行如下语句(PS:下面中间的英文不用管)
git submodule init
git submodule update
XGBoost support both build by MSVC or MinGW. Here is how you can build xgboost library using MinGW.
After installing Git for Windows, you should have a shortcut Git Bash. All the following steps are in the Git Bash.
To build with Visual Studio 2013 use cmake. Make sure you have a recent version of cmake added to your path and then from the xgboost directory:
mkdir build
cd build
cmake .. -G"Visual Studio 12 2013 Win64"
运行结果:
D:\迅雷下载\xgboost\build>cmake .. -G”Visual Studio 12 2013 Win64”
– The C compiler identification is MSVC 18.0.21005.1
– The CXX compiler identification is MSVC 18.0.21005.1
– Check for working C compiler: E:/vs2013/VC/bin/x86_amd64/cl.exe
– Check for working C compiler: E:/vs2013/VC/bin/x86_amd64/cl.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working CXX compiler: E:/vs2013/VC/bin/x86_amd64/cl.exe
– Check for working CXX compiler: E:/vs2013/VC/bin/x86_amd64/cl.exe – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Try OpenMP C flag = [/openmp]
– Performing Test OpenMP_FLAG_DETECTED
– Performing Test OpenMP_FLAG_DETECTED - Success
– Try OpenMP CXX flag = [/openmp]
– Performing Test OpenMP_FLAG_DETECTED
– Performing Test OpenMP_FLAG_DETECTED - Success
– Found OpenMP: /openmp
– Found PythonInterp: E:/Anaconda/python.exe (found version “2.7.9”)
– Configuring done
– Generating done
– Build files have been written to: D:/迅雷下载/xgboost/build
D:\迅雷下载\xgboost\build>
说明:注意指定为自己的VS编译器型号,我的是vs2013 win64版本,根据自己的版本选择,包括15 2017,14 2015,12 2013,11 2012,10 2010,9 2008,8 2005。
使用VS打开build目录下的xgboost.sln
按下图编译:
编译之后的结果:
lib目录下多出了libxgboost.dll文件
将libxgboost.dll 拷贝到python-package\xgboost。
检查distutils模块是否安装,进入python后import一下就知道,没装的自己安装,通常都会有的,安装好后进入bash终端:
cd python-package
python setup.py install
完成安装。
此时,此时,在Anaconda3的site-packages中出现了xgboost-0.6-py3.6.egg文件夹,如下图:
3.测试环境
进入终端:
python
import xgboost
并未出现:ImportError: Nomodule named xgboost,说明安装成功了。
启动Spyder也可以同样导入XGBoost。
在Spyder中