Windows下安装 XGBoost
Installing XGBoost For Anaconda on Windows
因为之前在Windows下安装起来好麻烦,而在Linux下很方便也很快搞定,于是一直在Ubuntu上用,然后前几天系统被我搞崩了,运行了一条 -f 命令,然后不小心删了太多系统的东西,然后。。。
用回Windows先吧。
首先,要有这三个:
- A Python installation such as Anaconda.
- Git
- MINGW
我的是 python3 和 anaconda3,现在装的时候已经可以给你加上环境变量什么的了,所以这两个装起来很容易的。而且 pip、numpy什么的都有了。
安装 git:
https://git-scm.com/download/win
安装 mingw-w64
这个要注意了。
- 下载地址:
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/5.3.0/threads-win32/seh/ - 点击下载
x86_64-5.3.0-release-win32-seh-rt_v4-rev0.7z
,适用64位操作系统。 - 解压到某一目录下,我放到了自己新建的一个 XGBoost下。(目录最好不要有中文字符)
- 配置环境变量。将
D:/XGBoost/mingw64/bin;
粘贴到path环境变量下。 - 进入目录
D:/XGBoost/mingw64/bin
,找到mingw32-make.exe 更名为make(为了使用方便)。成功后,在cmd下输入make会返回“make: *** No targets specified and no makefile found. Stop.”
。
这个搞定了。
然后,在你想装XGBoost的文件夹中,右键,git bash。进入命令行。
依次输入:
- git clone --recursive https://github.com/dmlc/xgboost
- cd xgboost
- git submodule init
- git submodule update
- 首先进入xgboost目录下:
cd (xgboost路径)
- 接着输入:
cp make/mingw64.mk config.mk
- 接着输入:
make -j4
打开 cmd
- 进入xgboost路径下的python-package:
cd python-package
- 接着输入:
python setup.py install
- OK
最后打开python命令行:import xgboost
如果没有报错,就安装成功了。
最后!!!
我装的时候出现错误了:
.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
差不多是这样的:
上网找了会,然后知道了。缺少 xgboost.dll
上这个地址下载:
http://www.picnet.com.au/blogs/guido/post/2016/09/22/xgboost-windows-x64-binaries-for-download/
然后放到 xgboost/python-package/xgboost
Copy the .dll file into the xgboost/python-package/xgboost folder
然后重新安装一下: python setup.py install
这下子可以了,回头一看其实也并不是很复杂。