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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33749735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:54:42  来源:igfitidea点击:

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

pythonpython-2.7installationmachine-learningxgboost

提问by Robin1988

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

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

On the homepage of xgboost(above link), it says: To install XGBoost, do the following steps:

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

  1. You need to run makein the root directory of the project

  2. In the python-package directory run

    python setup.py install

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

  2. 在 python-package 目录中运行

    python setup.py 安装

However, when I did it, for step 1 the following error appear: make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

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

then I skip step1 and did step 2 directly, another error appear:

然后我跳过步骤1并直接执行步骤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?

Does anyone know how to install xgboost for python on Windows10 platform? Thanks for your help!

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

采纳答案by Vu Anh

I installed XGBoost successfully in Windows 8 64bit, Python 2.7 with Visual Studio 2013 (don't need mingw64)

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

Updated 15/02/2017

2017 年 2 月 15 日更新

With newer version of XGBoost, here are my steps

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

Step 1.Install cmake https://cmake.org/download/

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

Verify cmakehave been installed successfully

验证是否cmake安装成功

$ cmake
Usage

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

Step 2.Clone xgboost source

步骤 2.克隆 xgboost 源

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

Step 3.Create Visual Studio Project

步骤 3.创建 Visual Studio 项目

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

Step 4.Build Visual Studio 2013 project

步骤 4.构建 Visual Studio 2013 项目

  • Open file xgboost_dir/build/ALL_BUILD.vcxprojwith Visual Studio 2013
  • In Visual Studio 2013, open BUILD > Configuration Manager...
    • choose Release in Active solution configuration
    • choose x64 in Active solution platform
  • Click BUILD > Build Solution (Ctrl + Shift +B)
  • xgboost_dir/build/ALL_BUILD.vcxproj使用 Visual Studio 2013打开文件
  • 在 Visual Studio 2013 中,打开 BUILD > Configuration Manager...
    • 在活动解决方案配置中选择发布
    • 在 Active 解决方案平台中选择 x64
  • 单击构建 > 构建解决方案(Ctrl + Shift + B)

After build solution, two new files libxgboost.dlland xgboost.exeare created in folder xgboost_dir/lib

之后构建的解决方案,两个新文件libxgboost.dll,并xgboost.exe在文件夹中创建xgboost_dir/lib

Step 5.Build python package

步骤 5.构建 python 包

  • Copy file libxgboost.dllto xgboost_dir/python-package
  • Change directory to xgboost_dir/python-packagefolder
  • Run command python setup.py install
  • 将文件复制libxgboost.dllxgboost_dir/python-package
  • 将目录更改为xgboost_dir/python-package文件夹
  • 运行命令 python setup.py install

Verify xgboost have been installed successfully

验证 xgboost 已成功安装

$ python -c "import xgboost"

Old Answer

旧答案

Here are my steps:

这是我的步骤:

  1. git clone https://github.com/dmlc/xgboost
  2. git checkout 9bc3d16
  3. Open project in xgboost/windowswith Visual Studio 2013
  4. In Visual Studio 2013, open BUILD > Configuration Manager...,
    • choose Releasein Active solution configuration
    • choose x64in Active solution platform
  5. Rebuild xgboost, xgboost_wrapper
  6. Copy all file in xgboost/windows/x64/Releasefolder to xgboost/wrapper
  7. Go to xgboost/python-package, run command python setup.py install
  8. Check xgboost by running command python -c "import xgboost"
  1. git 克隆https://github.com/dmlc/xgboost
  2. git 结帐 9bc3d16
  3. xgboost/windows使用 Visual Studio 2013打开项目
  4. 在 Visual Studio 2013 中,打开BUILD > Configuration Manager...,
    • 选择ReleaseActive solution configuration
    • 选择x64Active solution platform
  5. 重建xgboostxgboost_wrapper
  6. 将文件xgboost/windows/x64/Release夹中的所有文件复制到xgboost/wrapper
  7. 转到xgboost/python-package,运行命令python setup.py install
  8. 通过运行命令检查 xgboost python -c "import xgboost"

回答by user5733275

After build the c++ version, copy the release dll and lib files in ../windows/x64/Release/..(if you build x64 version) to ../wrapper/ then run python setup.py install

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

回答by Falconic

I followed the steps listed in https://www.kaggle.com/c/otto-group-product-classification-challenge/forums/t/13043/run-xgboost-from-windows-and-python. I will summarize what I did below.

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

1) Download Visual Basic Studio. You can download the community edition at visual studio website. There is a "free visual studio button on the upper right corner"

1) 下载 Visual Basic Studio。您可以在 Visual Studio 网站上下载社区版。右上角有个“免费的visual studio按钮”

2) Copy all content from the git hub repository of xgboost/tree/master/windows and Open Visual studio existing project on Visual studio

2) 从 xgboost/tree/master/windows 的 git hub 存储库中复制所有内容并在 Visual Studio 上打开 Visual Studio 现有项目

3) There are a couple of drop down menus you need to select ( "Release" and "X64" and then select build --> build all from the upper menu. It should look something like the attached screenshot.

3) 您需要选择几个下拉菜单(“Release”和“X64”,然后从上方菜单中选择 build --> build all。它应该看起来像附加的屏幕截图。

4) if you see the message ========== Build: 3 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========, it is all good

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

5) Browse to python-packages folder where the setup file for XGB resides and run the install command 'python setup.py install'.

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

You can find a similar thread at Install xgboost under python with 32-bit msys failing

你可以在Install xgboost under python with 32-bit msys failed找到一个类似的线程

Hope this helps.

希望这可以帮助。

回答by Disco4Ever

Note that as of the most recent release the Microsoft Visual Studio instructions no longer seem to apply as this link returns a 404 error:

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

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

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

You can read more about the removal of the MSVC build from Tianqi Chen's comment here.

您可以在此处从 Tianqi Chen 的评论中阅读有关移除 MSVC 构建的更多信息。

So here's what I did to finish a 64-bit build on Windows:

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

  1. Download and install MinGW-64: http://sourceforge.net/projects/mingw-w64/
  2. On the first screen of the install prompt make sure you set the Architecture to x86_64and the Threads to win32
  3. I installed to C:\mingw64 (to avoid spaces in the file path) so I added this to my PATH environment variable: C:\mingw64\mingw64\bin
  4. I also noticed that the make utility that is included in bin\mingw64 is called mingw32-makeso to simplify things I just renamed this to make
  5. Open a Windows command prompt and type gcc. You should see something like "fatal error: no input file"
  6. Next type make. You should see something like "No targets specified and no makefile found"
  7. Type git. If you don't have git, install it and add it to your PATH.
  1. 下载并安装 MinGW-64:http: //sourceforge.net/projects/mingw-w64/
  2. 在安装提示的第一个屏幕上,确保将 Architecture 设置为x86_64,将 Threads 设置为win32
  3. 我安装到 C:\mingw64(以避免文件路径中出现空格)所以我将它添加到我的 PATH 环境变量中:C:\mingw64\mingw64\bin
  4. 我还注意到 bin\mingw64 中包含的 make 实用程序称为mingw32-make,因此为了简化事情,我刚刚将其重命名为make
  5. 打开 Windows 命令提示符并键入 gcc。您应该会看到类似“致命错误:没有输入文件”的内容
  6. 下一个类型make。您应该会看到类似“未指定目标且未找到 makefile”之类的内容
  7. 输入 git。如果您没有 git,请安装它并将其添加到您的 PATH。

These should be all the tools you need to build the xgboost project. To get the source code run these lines:

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

  1. cd c:\
  2. git clone --recursive https://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
  1. CDC:\
  2. git clone --recursive https://github.com/dmlc/xgboost
  3. cd xgboost
  4. git子模块初始化
  5. git子模块更新
  6. cp make/mingw64.mk config.mk
  7. 制作 -j4

Note that I ran this part from a Cygwin shell. If you are using the Windows command prompt you should be able to change cp to copy and arrive at the same result. However, if the build fails on you for any reason I would recommend trying again using cygwin.

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

If the build finishes successfully, you should have a file called xgboost.exe located in the project root. To install the Python package, do the following:

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

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

Now you should be good to go. Open up Python, and you can import the package with:

现在你应该可以走了。打开 Python,您可以使用以下命令导入包:

import xgboost as xgb

To test the installation, I went ahead and ran the basic_walkthrough.py file that was included in the demo/guide-python folder of the project and didn't get any errors.

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

回答by Aman Gill

You can install xGBoost using either Visual Studio or minGW. Since, the official xgboost website says that MSVC build is not yet updated, I tried using mingw64. I am running xgboost (python package) on my win7 x64. Steps I followed were:

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

1) Follow Disco4Ever's steps for ming64 installation (mentioned above in the answers).

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

2) Install Git for windows. windows download link. This will also install Git Bash. Add git-installation-directory\cmd to your system environment variable PATH list.

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

3) Now clone xGBoost in desired location. Type the following in cmd:

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) In xgboost's root directory there should be a shell script named "build". Open it. It'll open up a Git Bash and start building. After building, xgboost.exe file will be created.

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

5) Now install python package :

5)现在安装python包:

cd python-package
python setup.py install

You can test by importing xgboost in python.

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

回答by Bolaka

It took a whole day, but I successfully installed xgboost on windows 7 64-bit box using TDM-GCCwith OpenMP enabled, instead of MingWfollowing this link - http://dnc1994.com/2016/03/installing-xgboost-on-windows/

花了一整天的时间,但我使用启用了 OpenMP 的TDM-GCC在 Windows 7 64 位机器上成功安装了 xgboost ,而不是按照此链接使用MingW- http://dnc1994.com/2016/03/installing-xgboost-on -视窗/

回答by jim

To add to the solution by Disco4ever for those attempting to build on 32bit Windows machines.

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

After doing step 6 and creating a config.mk file you need to go into this file and edit the following lines to remove the -m64 flag

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

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

回答by George Liu

Here's a very helpful link with important pointsto pay attention to during installation. It's very important to install "openmp". Otherwise you'll get error message.

这是一个非常有用的链接,其中包含安装过程中需要注意的要点。安装“openmp”非常重要。否则你会收到错误信息。

The link provides a step by step instruction for installing. Here's some quote:

该链接提供了安装的分步说明。这是一些引用:

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.

构建 Xgboost

公平地说,在 Windows 上安装 xgboost 的官方指南并没有错。但是,我还是想在这里强调几点以节省您的时间。

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.

Makefile_win 是原始 Makefile 的修改版本(感谢 Zhou Xiyou),以适应 Windows 上的构建过程。您可以在这里获取或下载它。一定要使用 UNIX shell,因为 Windows CMD 有 mkdir -p 命令的问题。推荐使用 Git Bash。一定要在 git clone 中使用 --recursive 选项。请务必使用适当的 MinGW。推荐使用 TDM-GCC。请注意,默认情况下它不会为您安装 OpenMP。您需要指定它,否则建筑物将失败。

Another helpful link is the official procedure: official guide

另一个有用的链接是官方程序:官方指南

Good luck!

祝你好运!

回答by boral

I would like to add a small workaround to Disco4ever 's solution.

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

For me I was unable to perform cloning in cygwin. So the workaround is perform it in command prompt in windows and do the rest of the task in cygwin.

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

Use cd c:\xgboost in the 3rd line to make it work in cygwin. So the updated last part is like this.

在第 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

And after installation is complete you can uninstall git and cygwin but xgboost and mingw64 must be kept as it is.

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

回答by ezchx

Adding "git checkout 9a48a40" to Disco4Ever's solution above worked for me:

在上面的 Disco4Ever 解决方案中添加“git checkout 9a48a40”对我有用:

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

This was originally posted by Cortajarena here: https://github.com/dmlc/xgboost/issues/1267

这最初由 Cortajarena 在这里发布:https: //github.com/dmlc/xgboost/issues/1267

Also, for what it's worth, I originally had 32 bit Python running on my 64 bit machine and I had to upload 64 bit Python for XGBoost to work.

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