简体   繁体   English

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

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

I am a new Python user.我是 Python 的新用户。 I downloaded the latest Anaconda 3 2.4.1 (Python 3.5) from the below link: https://www.continuum.io/downloads我从以下链接下载了最新的 Anaconda 3 2.4.1 (Python 3.5): https://www.continuum.io/downloads

My PC Configurations are: Windows 10, 64 bit, 4GB RAM我的电脑配置是:Windows 10、64 位、4GB RAM

I have spent hours trying to find the right way to download the package after the 'pip install xgboost' failed in the Anaconda command prompt but couldn't find any specific instructions for Anaconda.在 Anaconda 命令提示符下“pip install xgboost”失败后,我花了几个小时试图找到正确的方法来下载 package,但找不到 Anaconda 的任何具体说明。

Can anyone help on how to install xgboost from Anaconda?任何人都可以帮助如何从 Anaconda 安装 xgboost 吗?

The easiest way (Worked for me) is to do the following:最简单的方法(为我工作)是执行以下操作:

anaconda search -t conda xgboost

You will get a list of install-able features like this:您将获得一个可安装功能列表,如下所示:

在此处输入图片说明

for example if you want to install the first one on the list mndrake/xgboost (FOR WINDOWS-64bits):例如,如果您想安装mndrake/xgboost列表中的第一个(适用于 WINDOWS- 64 位):

conda install -c mndrake xgboost

If you're in a Unix system you can choose any other package with " linux-64 " on the right.如果您使用的是 Unix 系统,您可以选择右侧带有“ linux-64 ”的任何其他软件包。

  • Update on 22/10/2020: 22/10/2020 更新:

Without searching in conda list of channels, you can install it using (source: https://anaconda.org/anaconda/py-xgboost ) :无需在 conda 频道列表中搜索,您可以使用(来源: https : //anaconda.org/anaconda/py-xgboost )安装它:

conda install -c anaconda py-xgboost

Anaconda's website addresses this problem here: https://anaconda.org/anaconda/py-xgboost . Anaconda 的网站在这里解决了这个问题: https : //anaconda.org/anaconda/py-xgboost

conda install -c anaconda py-xgboost

This fixed the problem for me with no problems.这为我解决了问题,没有任何问题。

  1. Download package from this website .这个网站下载包。 I downloaded xgboost-0.6-cp36-cp36m-win_amd64.whl for anaconda 3 (python 3.6)我为anaconda 3(python 3.6)下载了xgboost-0.6-cp36-cp36m-win_amd64.whl
  2. Put the package in directory C:\\将包放在目录C:\\
  3. Open anaconda 3 prompt打开 anaconda 3 提示
  4. Type cd C:\\键入cd C:\\
  5. Type pip install C:\\xgboost-0.6-cp36-cp36m-win_amd64.whl输入pip install C:\\xgboost-0.6-cp36-cp36m-win_amd64.whl
  6. Type conda update scikit-learn输入conda update scikit-learn

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

conda install -c anaconda py-xgboost

I was able to install xgboost for Python in Windows yesterday by following this link .昨天我可以按照此链接在 Windows 中为 Python 安装 xgboost。 But when I tried to import using Anaconda, it failed.但是当我尝试使用 Anaconda 导入时,它失败了。 I recognized this is due to the fact that Anaconda has a different Python distribution.我认识到这是因为 Anaconda 有不同的 Python 发行版。 I then searched again and found this great article which made it!然后我再次搜索并找到了这篇很棒的文章

The trick is after installing successfully for regular Python, to have it work for Anaconda, you just need to pull up the Anaconda prompt and cd into this folder "code\\xgboost\\python-package", then run:诀窍是在为常规 Python 成功安装后,要使其适用于 Anaconda,您只需要拉起 Anaconda 提示符并将 cd 放入此文件夹“code\\xgboost\\python-package”,然后运行:

python setup.py install

And voila!瞧! The article says you need to add the path, but for me it worked directly.文章说你需要添加路径,但对我来说它直接起作用。 Good luck!祝你好运!

Also copied below the original contents in case the link is not available...如果链接不可用,也复制到原始内容下方...

Once the last command completes the build is done.一旦最后一个命令完成,构建就完成了。 We can now install the Python module.我们现在可以安装 Python 模块。 What follows depends on the Python distribution you are using.接下来的内容取决于您使用的 Python 发行版。 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>):对于 Anaconda,我将简单地使用 Anaconda 提示符,并在其中键入以下内容(在提示符之后,在我的情况下为 [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.让我们启动一个 notebook 来测试 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:为了避免它,我们必须将 g++ 运行时库的路径添加到 os 环境路径变量中:

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.然后我们可以导入 xgboost 并运行一个小例子。

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!我们都准备好了!

I'm able to install using the following commands (in Windows 10) :我可以使用以下命令进行安装(在 Windows 10 中):

conda install -c mikesilva xgboost

conda install -c conda-forge xgboost

GUYS ITS NOT THAT EASY:- PLEASE FOLLOW BELOW STEP TO GET TO MARK伙计们,这并不容易:- 请按照以下步骤进行标记

So here's what I did to finish a 64-bit build on Windows:所以这是我在 Windows 上完成 64 位构建所做的工作:

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

On the first screen of the install prompt make sure you set the Architecture to x86_64 and the Threads to win32 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(Please remove spaces)在安装提示的第一个屏幕上,确保将架构设置为 x86_64,将线程设置为 win32 我安装到 C:\\mingw64(以避免文件路径中出现空格),因此我将其添加到我的 PATH 环境变量中:C:\\ mingw64\\mingw64\\bin(请去掉空格)

I also noticed that the make utility that is included in bin\\mingw64 is called mingw32-make so to simplify things I just renamed this to make我还注意到 bin\\mingw64 中包含的 make 实用程序称为 mingw32-make,因此为了简化事情,我刚刚将其重命名为 make

Open a Windows command prompt and type gcc.打开 Windows 命令提示符并键入 gcc。 You should see something like "fatal error: no input file"您应该会看到类似“致命错误:没有输入文件”的内容

Next type make.下一个类型make。 You should see something like "No targets specified and no makefile found"您应该会看到类似“未指定目标且未找到 makefile”之类的内容

Type git.输入 git。 If you don't have git, install it and add it to your PATH.如果您没有 git,请安装它并将其添加到您的 PATH。 These should be all the tools you need to build the xgboost project.这些应该是构建 xgboost 项目所需的所有工具。 To get the source code run these lines:要获取源代码,请运行以下几行:

  • cd c:\\ CDC:\\
  • git clone --recursive https://github.com/dmlc/xgboost git clone --recursive https://github.com/dmlc/xgboost
  • cd xgboost cd xgboost
  • git submodule init git子模块初始化
  • git submodule update git子模块更新
  • cp make/mingw64.mk config.mk cp make/mingw64.mk config.mk
  • make -j4 Note that I ran this part from a Cygwin shell. make -j4 请注意,我从 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.如果您使用的是 Windows 命令提示符,您应该能够将 cp 更改为复制并获得相同的结果。 However, if the build fails on you for any reason I would recommend trying again using cygwin.但是,如果由于任何原因构建失败,我建议您再次尝试使用 cygwin。

If the build finishes successfully, you should have a file called xgboost.exe located in the project root.如果构建成功完成,您应该在项目根目录中有一个名为 xgboost.exe 的文件。 To install the Python package, do the following:要安装 Python 包,请执行以下操作:

  • cd python-package cd python 包
  • python setup.py install Now you should be good to go. python setup.py install 现在你应该可以开始了。 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. import xgboost as xgb 为了测试安装,我继续运行了包含在项目的 demo/guide-python 文件夹中的 basic_walkthrough.py 文件,没有出现任何错误。

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

if you found an issue when you try to import xgboost (my case it is Windows 10 and anaconda spyder) do the following:如果您在尝试导入 xgboost 时发现问题(我的情况是 Windows 10 和 anaconda spyder),请执行以下操作:

  1. Click on the windows icon (start button!)单击 Windows 图标(开始按钮!)
  2. Select and expand the anaconda folder选择并展开anaconda文件夹
  3. Run the Anaconda Prompt (as Administrator)运行 Anaconda Prompt(以管理员身份)
  4. Type the following command as it is mentioned in https://anaconda.org/anaconda/py-xgboost键入以下命令,因为它在https://anaconda.org/anaconda/py-xgboost 中提到

conda install -c anaconda py-xgboost conda install -c anaconda py-xgboost

在此处输入图片说明

That's all...Good luck.就是这样……祝你好运。

Try running this on Anaconda prompt尝试在 Anaconda 提示符下运行它

pip install xgboost

This worked for me on Spyder with Python 3.5这对我使用 Python 3.5 的 Spyder 有用

I figured out easy way to install XgBoost by mix of what is mentioned here .我想出了通过混合这里提到的内容来安装 XgBoost 的简单方法。

Step 1: Install gitbash from here and start gitbash.第 1 步:从这里安装 gitbash 并启动 gitbash。

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

Step 3: git submodule init第 3 步: git submodule init

       git submodule update

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

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

step 6: Goto Anaconda prompt and if you have a conda environment then activate that environment like my was py35 so I activate it by typing activate py35第 6 步:转到 Anaconda 提示符,如果您有 conda 环境,则像我的 py35 一样激活该环境,因此我通过键入 activate py35 来激活它

cd python-package
python setup.py install

step 7: setup the Path in system environment variable to the path where you installed xgboost/python-package.步骤 7:将系统环境变量中的 Path 设置为您安装 xgboost/python-package 的路径。

在您的 conda 提示符中使用它:

python -m pip install xgboost

The package directory states that xgboost is unstable for windows and is disabled:包目录指出 xgboost 对于 windows 不稳定并且被禁用:

pip installation on windows is currently disabled for further invesigation, please install from github. Windows 上的 pip 安装目前已禁用以进行进一步调查,请从 github 安装。

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

Anaconda3 version 4.4.0 check image转到 Anaconda -> Environments -> 从下拉列表中选择未安装 -> 如果您可以看到 xgboost pr Py-xgboost 选择并单击应用。

The following worked for me以下对我有用

conda install libxgboost conda 安装 libxgboost

There are a lot of dependencies of anaconda that have changed over the past years and won't work if you used them now. anaconda 的许多依赖项在过去几年中发生了变化,如果您现在使用它们,它们将无法工作。 Some of the answers need serious updation.一些答案需要认真更新。

I found this command did the job for me :我发现这个命令为我完成了这项工作:

conda install -c conda-forge xgboost

You may also want to look at the official documentation of anaconda for xgboost:您可能还想查看 anaconda for xgboost 的官方文档:

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

I have used this command and it worked for me.我已经使用了这个命令,它对我有用。

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

打开 anaconda prompt 并运行

pip install xgboost

您可以使用pip安装它:

pip3 install --default-timeout=100 xgboost
conda install -c anaconda py-xgboost

This simple helped me you don't have to include anything at the end because if you include something, some of your packages will be upgraded but some will be downgraded.这个简单帮助我你不必在最后包含任何东西,因为如果你包含一些东西,你的一些包将被升级,但有些会被降级。 You can get this from this url: https://anaconda.org/anaconda/py-xgboost你可以从这个网址得到这个: https : //anaconda.org/anaconda/py-xgboost

conda install -c anaconda py-xgboost 
  1. Look here https://github.com/Rafi993/xgboost/ for building xgboost on your machine.看这里https://github.com/Rafi993/xgboost/在你的机器上构建 xgboost。 There are many different varieties of the solution above, but it seems that the version in the link above is the good one.上面的解决方案有很多不同的变体,但似乎上面链接中的版本是好的。 At least that worked for me: I've tested it on Windows 7 and Windows Server 2008.至少这对我有用:我已经在 Windows 7 和 Windows Server 2008 上对其进行了测试。

  2. Then run the following commands in cmd in order to install python bindings:然后在 cmd 中运行以下命令以安装 python 绑定:
    cd python-package python setup.py install

  3. You might also need a proper mingw (google for tdm-gcc) and the latest setuptools from anaconda.您可能还需要一个合适的 mingw(tdm-gcc 的谷歌)和来自 anaconda 的最新安装工具。

I hope it will help我希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM