64位win10下xgboost python包安装

本文详细介绍了在64位Windows 10系统和Python 2.7.11环境中安装xgboost Python包的步骤。包括安装mingw-w64、Git、Cygwin、pip、依赖包numpy和scipy等前置条件,最终通过编译源码的方式成功安装xgboost。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

64位win10下安装xgboost python包的教程

转载文章,原文链接http://blog.csdn.net/zyghs/article/details/50897716

xgboost的 Python包在windows环境下使用MicrosoftVisual Studio安装的功能被陈天奇大神删掉了,如下是comment:

因此相关的教程网页https://github.com/dmlc/xgboost/tree/master/windows也404了,为了不抛弃windows环境,在尝试若干方法都失败后,找到了以下可以成功的方法。复杂了一些,但是能用。不建议在网上找xgboost旧版本尝试安装,虽然也可能成功。

一、操作环境的确认

platform:windows 10,64位

Python: Python2.7.11 64位

1、如果是64位操作系统,务必保证Python也是64位,不然到最后会出现“WindowsError:[Error 193] %1 不是有效的 Win32”这样的错误,这是由Python和操作系统位数混用造成的2、Python版本用2.7做测试,64位的Python3应该也没问题。

附1:如何查看你的Python版本:

方法一:打开Python IDE(或者在windows的cmd里输入python)看到“64bit(amd64)”就是64位Python。


方法二:在Python IDE里输入:

[python] view plain copy
print ?
  1. import sys, platform  
  2. platform.architecture()  
import sys, platform
platform.architecture()

 如果返回(‘64bit’,’WindowsPE’)也说明是64位。

附2:确认安装完Python后把C:\Python27;添加到系统环境变量,否则后续步骤中命令行下“Python”令不能使用.

二、mingw-w64的安装

mingw-w64是为了在windows环境下直接编译github上得到的xgboost项目文件

1、下载地址:

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位操作系统。

另外,建议不要使用mingw-w64-install.exe(170.0 kB)在线下载,因为在选择安装版本后下载有些版本会崩掉(比如本版本)。

2、解压到某一目录下,我放到了C盘根目录。(目录最好不要有中文字符)

3、配置环境变量。将C:\mingw64\bin;粘贴到path环境变量下,用“;”隔开。

我的电脑图标->右键->属性->高级系统设置->选择“高级”选项->选择下面“环境变量”->用户变量或者系统变量均可,若无path则创建一个path变量。

4、进入目录C:\mingw64\bin,找到mingw32-make.exe 更名为make(为了使用方便)。成功后,在cmd下输入make会返回“make: *** No targets specified and no makefile found.  Stop.”。

三、Git的安装

git在安装xgboost安装中的作用不大,但是为了自动获取github上最新的xgboost包,还是安装一下,以后也会用到这个工具。

这是官方下载地址:https://git-scm.com/download/win  (32位版本也能用)

在安装四个步骤的过程中,我依次选择的是




成功后,在cmd下输入git会出现git的帮助信息。

四、Cygwin选装

cygwin是windows平台上运行的unix模拟环境。后续步骤需要在命令行下操作,虽然cmd和git的shell也可以(亲测在Cygwin下没出现问题)。如果感觉此包不错,可以作为选择安装。

官网下载地址:https://cygwin.com/install.html

64位机点击

安装快慢视选择的功能包的数量而定,最后一步选择下载点时,随便选一个(如)就行。

五、pip的安装

pip是安装扩展名为.whl的python包用的工具。

1、下载地址:https://pypi.python.org/pypi/pip#downloads   选择第二项


,解压到一个目录下,比如D: 。

2、找到所在目录,在cmd里切换到此目录,并输入执行

  1. python setup.py install  
python setup.py install
指令。

3、把C:\Python27\Scripts;添加到系统环境变量。

4、重启cmd,输入pip,显示pip的帮助信息,则安装成功。


六、numpy和scipy的安装

numpy和scipy是xgboost的依赖工具包,python下进行科学计算也是必不可少的工具。

1、下载地址:

numpy:http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

scipy:  http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy  均下载对应python版本号的的whl文件(如scipy-0.17.0-cp27-none-win_amd64.whl和numpy-1.10.4+mkl-cp27-cp27m-win_amd64.whl)

2、将两个whl文件粘贴到C:\Python27\Scripts目录下。

3、在cmd下运行

  1. pip install XXXXX.whl  
pip install XXXXX.whl

(XXXXX为文件名)进行安装。

4、成功后在python IDE下执行

  1. import numpy  
import numpy
  1. import scipy  
import scipy

 
 

如果没有错误提示,就安装成功了。

七、安装xgboost

做了那么多准备工作,终于要执行关键步骤了。

1、在git bash或者Cygwin下依次执行以下七个步骤:

  1. cd c:  
  2. git clone –recursivehttps://github.com/dmlc/xgboost  
  3. cd xgboost  
  4. git submodule init  
  5. git submodule update  
  6. cp make/mingw64.mk config.mk  
  7. make -j4  
cd c:
git clone --recursivehttps://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
cp make/mingw64.mk config.mk
make -j4

如果是在cmd下执行,cp指令要换成copy(我换了之后还有错,改用cygwin)。

make成功后继续执行:

  1. cd python-package  
  2. python setup.py install  
cd python-package
python setup.py install

此时基本大功告成。

2、在python的IDE下执行

[python] view plain copy
print ?
  1. import xgboost  
import xgboost
 如果没有报错,就安装成功了。 
 


附录:参考资料

http://stackoverflow.com/questions/33749735/how-to-install-xgboost-package-in-python-windows-platform

http://blog.csdn.net/yijichangkong/article/details/44278445

http://blog.csdn.net/liuguobo/article/details/19118277

http://www.tuicool.com/articles/eiM3Er3/

http://jingyan.baidu.com/article/19192ad816ea01e53e570730.html

http://bbs.csdn.net/topics/390796542

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值