如何在 Anaconda Python(Windows 平台)中安装 xgboost?

How to install xgboost in Anaconda Python (Windows platform)?

我是新 Python 用户。我从下面 link 下载了最新的 Anaconda 3 2.4.1 (Python 3.5): https://www.continuum.io/downloads

我的电脑配置是:Windows10、64 位、4GB 内存

在 Anaconda 命令提示符 'pip install xgboost' 失败后,我花了几个小时试图找到正确的下载包的方法,但找不到任何关于 Anaconda 的具体说明。

任何人都可以帮助了解如何从 Anaconda 安装 xgboost 吗?

包目录指出 xgboost 在 windows 中不稳定并被禁用:

pip installation on windows is currently disabled for further invesigation, please install from github.

https://pypi.python.org/pypi/xgboost/

昨天 by following this link. But when I tried to import using Anaconda, it failed. I recognized this is due to the fact that Anaconda has a different Python distribution. I then searched again and found this great article 我在 Windows 中为 Python 安装了 xgboost!

诀窍是在为常规 Python 安装成功后,要让它在 Anaconda 上工作,你只需要拉起 Anaconda 提示符并 cd 到这个文件夹 "code\xgboost\python-package",然后 运行:

python setup.py install

瞧!文章说你需要添加路径,但对我来说它直接起作用了。祝你好运!

如果 link 不可用,请复制到原始内容下方...

Once the last command completes the build is done. We can now install the Python module. What follows depends on the Python distribution you are using. For Anaconda, I will simply use the Anaconda prompt, and type the following in it (after the prompt, in my case [Anaconda3] C:\Users\IBM_ADMIN>):

[Anaconda3] C:\Users\IBM_ADMIN>cd code\xgboost\python-package
The point is to move to the python-package directory of XGBoost.  Then type:
[Anaconda3] C:\Users\IBM_ADMIN\code\xgboost\python-package>python setup.py install

We are almost done. Let's launch a notebook to test XGBoost. Importing it directly causes an error. In order to avoid it we must add the path to the g++ runtime libraries to the os environment path variable with:

import os

mingw_path = 'C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin'

os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']

We can then import xgboost and run a small example.

import xgboost as xgb 
import numpy as np
data = np.random.rand(5,10) # 5 entities, each contains 10 features
label = np.random.randint(2, size=5) # binary target
dtrain = xgb.DMatrix( data, label=label)

dtest = dtrain

param = {'bst:max_depth':2, 'bst:eta':1, 'silent':1, 'objective':'binary:logistic' }
param['nthread'] = 4
param['eval_metric'] = 'auc'

evallist  = [(dtest,'eval'), (dtrain,'train')]

num_round = 10
bst = xgb.train( param, dtrain, num_round, evallist )

bst.dump_model('dump.raw.txt')

We are all set!

  1. 查看此处 https://github.com/Rafi993/xgboost/ 在您的机器上构建 xgboost。上面的解决方案有很多种,但似乎上面 link 中的版本是好的。至少这对我有用:我已经在 Windows 7 和 Windows Server 2008 上测试过它。

  2. 然后 运行 在 cmd 中执行以下命令以安装 python 绑定:
    cd python-package python setup.py install

  3. 您可能还需要一个合适的 mingw(google 对于 tdm-gcc) 以及来自 anaconda 的最新设置工具。

希望对你有所帮助

伙计们没那么容易:- 请按照以下步骤进行标记

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

下载并安装 MinGW-64:sourceforge.net /projects/mingw-w64/

在安装提示的第一个屏幕上,确保将体系结构设置为 x86_64 并将线程设置为 win32 我安装到 C:\mingw64(以避免文件路径中有空格)所以我将其添加到我的 PATH 环境变量中:C:\mingw64\mingw64\bin(请删除空格)

我还注意到 bin\mingw64 中包含的 make 实用程序称为 mingw32-make 所以为了简化我只是将其重命名为 make

打开 Windows 命令提示符并键入 gcc。您应该会看到类似 "fatal error: no input file"

的内容

接下来输入 make。您应该会看到类似 "No targets specified and no makefile found"

的内容

键入 git。如果您没有 git,请安装它并将其添加到您的 PATH 中。 这些应该是构建 xgboost 项目所需的所有工具。要获取源代码 运行 这些行:

  • cd c:\
  • git 克隆 --递归 https://github.com/dmlc/xgboost
  • cd xgboost
  • git 子模块初始化
  • git 子模块更新
  • cp make/mingw64.mk config.mk
  • 制作-j4 请注意,我 运行 这部分来自 Cygwin shell。如果您使用 Windows 命令提示符,您应该能够将 cp 更改为复制并获得相同的结果。但是,如果由于任何原因构建失败,我建议使用 cygwin 再试一次。

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

  • cd python-包
  • python setup.py 安装 现在你应该可以开始了。打开Python,你可以导入包:

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

您可以将xgboost包下载到本地,最好将xgboost源文件放在D:\或C:\下(ps:下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost,select "xgboost-0.6-cp35-cp35m-win_amd64.whl",但这取决于您的操作系统),然后打开 Anaconda 提示符,输入 pip install D:\xgboost-0.6-cp35-cp35m-win_amd64.whl,那么你就可以成功地将xgboost安装到你的anaconda中了

最简单的方法(对我有用)是执行以下操作:

anaconda search -t conda xgboost

您将获得如下所示的可安装功能列表:

例如,如果您想安装列表中的第一个 mndrake/xgboost(对于 WINDOWS-64 位):

conda install -c mndrake xgboost

如果您使用的是 Unix 系统,您可以选择右侧带有“linux-64”的任何其他软件包。

  • 2020 年 10 月 22 日更新:

无需在 conda 频道列表中搜索,您可以使用(来源:https://anaconda.org/anaconda/py-xgboost)安装它:

conda install -c anaconda py-xgboost

Anaconda 的网站在这里解决了这个问题:https://anaconda.org/anaconda/py-xgboost

conda install -c anaconda py-xgboost

这对我来说没有任何问题。

  1. this website 下载包。 我为 anaconda 3 (python 3.6)
  2. 下载了 xgboost-0.6-cp36-cp36m-win_amd64.whl
  3. 将包放入目录C:\
  4. 打开anaconda 3提示符
  5. 类型cd C:\
  6. 输入pip install C:\xgboost-0.6-cp36-cp36m-win_amd64.whl
  7. 类型conda update scikit-learn

我可以使用以下命令进行安装(在 Windows 10 中):

conda install -c mikesilva xgboost

conda install -c conda-forge xgboost

我找到了通过混合使用提到的方法安装 XgBoost 的简单方法 here

第一步: 从 here 安装 gitbash 并启动 gitbash。

第 2 步:git clone --recursive https://github.com/dmlc/xgboost

第 3 步:git submodule init

       git submodule update

第 4 步:alias make='mingw32-make'

第 5 步:cp make/mingw64.mk config.mk; make -j4

第 6 步:转到 Anaconda 提示符,如果你有 conda 环境,然后像我的 py35 一样激活该环境,所以我通过输入 activate py35

来激活它
cd python-package
python setup.py install

第 7 步:将系统环境变量中的 Path 设置为您安装的路径 xgboost/python-package。

Anaconda3 版本 4.4.0check image 转到 Anaconda -> Environments -> 从下拉菜单 select not installed -> 如果你能看到 xgboost pr Py-xgboost select 然后点击应用。

在尝试了一些东西之后,唯一对我有用的是:

conda install -c anaconda py-xgboost

这个简单的方法对我很有帮助,你不必在最后包含任何东西,因为如果你包含一些东西,你的一些包会升级,但有些会降级。 你可以从这个url得到这个:https://anaconda.org/anaconda/py-xgboost

conda install -c anaconda py-xgboost 

在你的 conda 提示中使用这个:

python -m pip install xgboost

如果您在尝试导入 xgboost 时发现问题(我的情况是 Windows 10 和 anaconda spyder),请执行以下操作:

  1. 单击 windows 图标(开始按钮!)
  2. Select 并展开 anaconda 文件夹
  3. 运行 Anaconda 提示符(作为管理员)
  4. 键入 https://anaconda.org/anaconda/py-xgboost
  5. 中提到的以下命令

conda install -c anaconda py-xgboost

就这些了...祝你好运。

以下对我有用:

conda install libxgboost

anaconda 的许多依赖项在过去几年中发生了变化,如果您现在使用它们将无法正常工作。一些答案需要认真更新。

我发现这个命令对我有用:

conda install -c conda-forge xgboost

你可能还想看看 anaconda for xgboost 的官方文档:

https://anaconda.org/conda-forge/xgboost

我用过这个命令,对我有用。

import sys
!{sys.executable} -m pip install xgboost

打开 anaconda 提示符并 运行

pip install xgboost

您可以使用 pip 安装它:

pip3 install --default-timeout=100 xgboost

在 Anaconda 提示符下尝试运行这个

pip install xgboost

这对我在 Python 3.5

的 Spyder 上有效