如何在 python(windows 平台)中安装 xgboost 包?

How to install xgboost package in python (windows platform)?

http://xgboost.readthedocs.org/en/latest/python/python_intro.html

在 xgboost 的主页上(link 以上),它说: 要安装 XGBoost,请执行以下步骤:

  1. 需要在项目根目录运行make

  2. 在python-package目录下运行

    python setup.py 安装

但是,当我这样做时,对于第 1 步,出现以下错误: make : 术语 'make' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查 名称拼写错误,或者如果包含路径,请验证路径是否正确,然后重试。

然后我跳过step1,直接做了step 2,又出现一个错误:

Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    LIB_PATH = libpath['find_lib_path']()
  File "xgboost/libpath.py", line 44, in find_lib_path
    'List of candidates:\n' + ('\n'.join(dll_path)))
__builtin__.XGBoostLibraryNotFound: Cannot find XGBoost Libarary in the candicate path, did you install compilers and run build.sh in root path?

有谁知道如何在 Windows10 平台上为 python 安装 xgboost?感谢您的帮助!

构建c++版本后,将../windows/x64/Release/..(如果构建x64版本)中的release dll和lib文件复制到../wrapper/ 然后运行 python setup.py 安装

我遵循了 https://www.kaggle.com/c/otto-group-product-classification-challenge/forums/t/13043/run-xgboost-from-windows-and-python 中列出的步骤。我将在下面总结我所做的。

1) 下载 Visual Basic Studio。您可以在 visual studio 网站下载社区版。有个"free visual studio button on the upper right corner"

2) 从 xgboost/tree/master/windows 的 git hub 存储库复制所有内容并打开 Visual studio Visual studio

上的现有项目

3) 有几个下拉菜单需要 select("Release" 和 "X64" 然后 select build --> build all from the上层菜单。它看起来应该类似于所附的屏幕截图。

4) 如果您看到消息 ========== Build: 3 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========,一切都很好

5) 浏览到 XGB 安装文件所在的 python-packages 文件夹和 运行 安装命令 'python setup.py install'.

您可以在 Install xgboost under python with 32-bit msys failing

找到类似的帖子

希望对您有所帮助。

我在 Windows 8 64 位、Python 2.7 和 Visual Studio 2013 中成功安装了 XGBoost(不需要 mingw64)

2017 年 2 月 15 日更新

使用较新版本的 XGBoost,这是我的步骤

步骤 1. 安装 cmake https://cmake.org/download/

验证 cmake 已成功安装

$ cmake
Usage

cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
...

步骤 2. 克隆 xgboost 源

$ git clone https://github.com/dmlc/xgboost xgboost_dir

步骤 3. 创建 Visual Studio 项目

$ cd xgboost_dir
$ mkdir build
$ cd build
$ cmake .. -G"Visual Studio 12 2013 Win64"

步骤 4. 构建 Visual Studio 2013 项目

  • 打开文件 xgboost_dir/build/ALL_BUILD.vcxproj Visual Studio 2013
  • 2013年Visual Studio开BUILD > Configuration Manager...
    • 在活动解决方案配置中选择发布
    • 在 Active 解决方案平台中选择 x64
  • 单击“构建”>“构建解决方案”(Ctrl + Shift +B)

构建解决方案后,在文件夹 xgboost_dir/lib

中创建了两个新文件 libxgboost.dllxgboost.exe

步骤 5. 构建 python 包

  • 将文件 libxgboost.dll 复制到 xgboost_dir/python-package
  • 将目录更改为 xgboost_dir/python-package 文件夹
  • 运行 命令 python setup.py install

验证 xgboost 是否已成功安装

$ python -c "import xgboost"

旧答案

这是我的步骤:

  1. git 克隆 https://github.com/dmlc/xgboost
  2. git结账9bc3d16
  3. xgboost/windows 中打开项目 Visual Studio 2013
  4. 2013年Visual Studio开BUILD > Configuration Manager...,
    • Active solution configuration
    • 中选择Release
    • Active solution platform
    • 中选择x64
  5. 重建 xgboostxgboost_wrapper
  6. xgboost/windows/x64/Release 文件夹中的所有文件复制到 xgboost/wrapper
  7. 转到 xgboost/python-package、运行 命令 python setup.py install
  8. 通过 运行ning 命令检查 xgboost python -c "import xgboost"

请注意,从最新版本开始,Microsoft Visual Studio 说明似乎不再适用,因为此 link returns 404 错误:

https://github.com/dmlc/xgboost/tree/master/windows

您可以从 Tianqi Chen 的评论中阅读更多关于删除 MSVC 构建的信息 here

下面是我在 Windows 上完成 64 位构建所做的工作:

  1. 下载并安装 MinGW-64:http://sourceforge.net/projects/mingw-w64/
  2. 在安装提示的第一个屏幕上,确保将体系结构设置为 x86_64 并将线程设置为 win32
  3. 我安装到 C:\mingw64(为了避免文件路径中出现空格)所以我将其添加到我的 PATH 环境变量中:C:\mingw64\mingw64\bin
  4. 我还注意到 bin\mingw64 中包含的 make 实用程序称为 mingw32-make 所以为了简化我只是将其重命名为 制作
  5. 打开 Windows 命令提示符并键入 gcc。您应该会看到类似 "fatal error: no input file"
  6. 的内容
  7. 接下来输入 make。您应该会看到类似 "No targets specified and no makefile found"
  8. 的内容
  9. 键入 git。如果您没有 git,请安装它并将其添加到您的 路径。

这些应该是您构建 xgboost 项目所需的所有工具。要获取源代码 运行 这些行:

  1. cd c:\
  2. git 克隆 --recursive https://github.com/dmlc/xgboost
  3. cd xgboost
  4. git 子模块初始化
  5. git 子模块更新
  6. cp make/mingw64.mk config.mk
  7. 制作-j4

请注意,我 运行 这部分来自 Cygwin shell。如果您使用 Windows 命令提示符,您应该能够将 cp 更改为复制并获得相同的结果。但是,如果由于任何原因构建失败,我建议使用 cygwin 再试一次。

如果构建成功完成,您应该在项目根目录中有一个名为 xgboost.exe 的文件。要安装 Python 包,请执行以下操作:

  1. cd python-包
  2. python setup.py 安装

现在你应该可以开始了。打开 Python,你可以导入包:

import xgboost as xgb

为了测试安装,我继续 运行 包含在项目 demo/guide-python 文件夹中的 basic_walkthrough.py 文件并且没有出现任何错误。

您可以使用 Visual Studio 或 minGW 安装 xGBoost。由于 xgboost 官方网站说 MSVC 构建尚未更新,我尝试使用 mingw64。 我在我的 win7 x64 上是 运行 xgboost(python 包)。我遵循的步骤是:

1) 按照 Disco4Ever 的 ming64 安装步骤(上面的答案中提到)。

2) 为 windows 安装 Git。 windows download link。这也将安装 Git Bash。将 git-installation-directory\cmd 添加到您的系统环境变量 PATH 列表中。

3) 现在将 xGBoost 克隆到所需位置。在 cmd 中输入以下内容:

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
cp make/mingw64.mk config.mk
make -j4

4) 在xgboost 的根目录中应该有一个名为"build" 的shell 脚本。打开它。它将打开 Git Bash 并开始构建。构建后,将创建 xgboost.exe 个文件。

5) 现在安装 python 包:

cd python-package
python setup.py install

您可以通过在 python 中导入 xgboost 进行测试。

花了一整天,但我使用 TDM-GCC with OpenMP enabled, instead of MingW following this link - http://dnc1994.com/2016/03/installing-xgboost-on-windows/

在 windows 7 64 位机器上成功安装了 xgboost

为那些试图在 32 位 Windows 机器上构建的人添加 Disco4ever 的解决方案。

完成第 6 步并创建 config.mk 文件后,您需要进入该文件并编辑以下行以删除 -m64 标志

export CXX=g++ -m64
export CC=gcc -m64

这里有一个very helpful link with important points安装时需要注意的地方。安装"openmp"非常重要。否则你会收到错误信息。

link 提供了安装的分步说明。这是一些引述:

Building Xgboost

To be fair, there is nothing wrong about the official guide for installing xgboost on Windows. But still, I’d love to stress several points here to save your time.

git clone --recursive https://github.com/dmlc/xgboost  
cd xgboost  
wget https://www.dropbox.com/s/y8myex4bnuzcp03/Makefile_win?dl=1
cp Makefile_win Makefile
cp make/mingw64.mk config.mk
mingw32-make

Makefile_win is a modified version (thanks to Zhou Xiyou) of the original Makefile to suit the building process on Windows. You can wget it or download it here. Be sure to use a UNIX shell for thi because Windows CMD has issue with mkdir -p command. Git Bash is recommended. Be sure to use --recursive option with git clone. Be sure to use a proper MinGW. TDM-GCC is recommended. Note that by default it wouldn’t install OpenMP for you. You need to specifiy it otherwise the building would fail.

另一个有用的link是官方程序:official guide

祝你好运!

我想为 Disco4ever 的解决方案添加一个小的解决方法。

对我来说,我无法在 cygwin 中执行克隆。因此,解决方法是在 windows 中的命令提示符下执行它,然后在 cygwin 中完成其余任务。

在第 3 行使用 cd c:\xgboost 使其在 cygwin 中工作。所以更新后的最后一部分是这样的

cd c:\
git clone --recursive https://github.com/dmlc/xgboost
cd c:\xgboost
git submodule init
git submodule update
cp make/mingw64.mk config.mk
make -j4

安装完成后可以卸载git和cygwin,但xgboost和mingw64必须保持原样。

将 "git checkout 9a48a40" 添加到上面的 Disco4Ever 解决方案对我有用:

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

这最初是由 Cortajarena 在此处发布的: https://github.com/dmlc/xgboost/issues/1267

此外,为了它的价值,我最初在我的 64 位机器上有 32 位 Python 运行,我必须上传 64 位 Python 才能让 XGBoost 工作。

感谢 disco4ever 的回答。我试图在我的 windows 10 64 位机器上为 Python Anaconda 环境构建 xgboost。使用 Git、mingw64 和基本 windows cmd.

在复制步骤之前一切都对我有用:cp make/mingw64.mk config.mk,因为我正在使用 windows cmd,所以我将其修改为复制 c: \xgboost\make\mingw64.mk c:\xgboost\config.mk

当我继续下一步:make -j4 时,我收到构建失败的错误消息。在经历了如此多的挫折之后,在这个阶段通过单击 build.sh(shell 脚本)只是厌倦了一些不同的东西。它开始执行并自动完成。

然后我执行了同样的步骤make -j4,令我惊叹的是构建成功了。我在我的 xgboost 文件夹中看到了最期待的 xgboost.exe 文件。

然后我继续执行进一步的步骤并执行 python setup.py 安装。最后一切都安装完美。然后我去了我的 spyder 并检查它是否在工作。但我离幸福只有一步之遥,因为我仍然看到导入错误。

关闭所有命令提示符(Anaconda、Git bash、Windows CMD、cygwin 终端)然后再次打开 spyder 并输入 'import xgboost'。成功,没有错误。

再次感谢大家。

如果有人正在寻找不需要自己编译的更简单的解决方案:

  1. here 下载 xgboost whl 文件(确保匹配您的 python 版本和系统架构,例如 "xgboost-0.6-cp35-cp35m-win_amd64.whl" for python 3.5 on 64-bit machine)
  2. 打开命令提示符
  3. cd 到您的下载文件夹(或保存 whl 文件的任何位置)
  4. pip install xgboost-0.6-cp35-cp35m-win_amd64.whl(或您的 whl 文件的任何名称)

如果您发现它由于缺少依赖项而无法安装,请先下载并安装依赖项,然后重试。

如果它抱怨访问权限,请尝试以管理员身份打开命令提示符并重试。

这为您提供了 xgboost 和 scikit-learn 包装器,让您不必经历自己编译的痛苦。 :)

我刚刚为我的 python 2.7 和 python 3.5、anaconda、64 位机器和 64 位 python.[ 安装了 xgboost =19=]

都非常简单,不需要 VS2013 或 git。

我认为它也适用于普通 python。

如果你使用python 3.5:

1:下载包here,版本取决于你的python版本,python3.5或python3.6,32位或64位。

2:使用命令window,使用cd将下载文件夹设为密码,然后使用

pip install filename.whl

好的,完成了。 有关更详细的步骤,请参阅

如果你使用python2.7,你不需要下载VS2013自己搭建,因为我已经搭建好了,你可以下载我搭建的文件直接安装

1:下载它here by google drive

2:下载,解压,粘贴到这里:

"your python path\Lib\site-packages"

那么你应该有这样的东西:

3: 在上面显示的 python-package 文件夹中,使用 cmd window,cd 那里和 运行

python setup.py install 

使用此代码

 import xgboost 

在你的python中检查你是否安装了mingw-64,没有错误信息说明你已经安装了mingw-64并且你已经完成了。

如果有错误信息

"WindowsError: [Error 126] "

说明你还没有安装mingw-64,还差一步

在此处下载 mingw-64:http://sourceforge.net/projects/mingw-w64/

安装mingw-64时选择x86_64而不是默认的"i686", 然后将 "your install path\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin;" 添加到您的 PATH,它应该是这样的:

"C:\Program Files\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin;"

(这是我的)

别忘了“;”在路径中。

那么你就完成了,可以使用

import xgboost 

在你的 python 中检查一下,是的!

PS:如果不知道怎么加路径,直接google找解决办法。别担心,很简单。

注意:在"make -j4"之前使用gcc -v检查你的gcc版本。

对于我来说,我的环境是win10 + anaconda(python 2.7),当我运行 make -j4.它显示 std::mutex 错误。在我使用 gcc- v 它回显 gcc4.7(anaconda 的默认 gcc)。在我选择我的 gcc 到 mingw64 的 6.2 gcc 之后,它就可以工作了。

最后,我使用“/d/Anaconda2/python.exe setup.py install”安装xgboost python packet.

您可以使用以下 3 个步骤安装 XGBoost:

  1. 收集您系统的信息(python 版本和系统架构 - 32 位或 64 位)

  2. https://www.lfd.uci.edu/~gohlke/pythonlibs/

  3. 下载相关.whl

例如如果你的 python 版本是 3.7 而 windows 是 32 位,那么合适的文件是:

xgboost‑0.72‑cp37‑cp37m‑win32.whl

  1. 运行 点安装 yourdownloadedfile.whl

您还可以找到详细步骤 here

如果您正在为特定项目安装 XGBoost 并且您正在使用 Pycahrm,那么您需要遵循以下步骤:

  1. Here下载xgboost‑0.72‑cp36‑cp36m‑win_amd64.whl(因为我使用的是Python 3.6,如果你使用不同版本的Python比如2.7那么你需要安装 xgboost‑0.72‑cp27‑cp27m‑win_amd64.whl).

  2. 将 复制到您的 Project Interpreter 目录。您可以通过单击Pycharm中的File -> Settings -> Project Interpreter找到Project Interpreter的目录。

  3. 打开命令提示符。从 cmd 转到项目解释器的目录。写入以下命令:pip install xgboost-0.72-cp36-cp36m-win_amd64.whl

在 windows 10 上,使用 python 3.6,下面的命令有效。

在Anaconda Prompt中,可以直接使用下面的命令。附上截图作为证据。 pip 安装 xgboost

我使用 Jupyter notebook,我发现了一种在 Anaconda 中安装 XGBoost 的非常简单的方法:

  1. 安装 Anaconda
  2. 打开 Anaconda Navigator
  3. 在环境中,更新索引并搜索 xgboost(未安装)
  4. 选择 libxgboost 和 py-xgboost 并单击 'Apply'

完成