如何在 Anaconda Python(Windows 平台)中安装 xgboost?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35139108/
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
How to install xgboost in Anaconda Python (Windows platform)?
提问by Siddharth Vashishtha
I am a new Python user. I downloaded the latest Anaconda 3 2.4.1 (Python 3.5) from the below link: https://www.continuum.io/downloads
我是一个新的 Python 用户。我从以下链接下载了最新的 Anaconda 3 2.4.1 (Python 3.5):https: //www.continuum.io/downloads
My PC Configurations are: Windows 10, 64 bit, 4GB RAM
我的 PC 配置是: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”失败后,我花了几个小时试图找到下载包的正确方法,但找不到任何针对 Anaconda 的具体说明。
Can anyone help on how to install xgboost from Anaconda?
任何人都可以帮助如何从 Anaconda 安装 xgboost?
采纳答案by deltascience
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”的任何其他软件包。
回答by C_Quinn
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 安装。
回答by George Liu
I was able to install xgboost for Python in Windows yesterday 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 articlewhich made it!
昨天,我可以按照此链接在 Windows 中为 Python 安装 xgboost 。但是当我尝试使用 Anaconda 导入时,它失败了。我认识到这是因为 Anaconda 有不同的 Python 发行版。然后我再次搜索并找到了这篇很棒的文章!
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. 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>):
一旦最后一个命令完成,构建就完成了。我们现在可以安装 Python 模块。接下来的内容取决于您使用的 Python 发行版。对于 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. 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:
我们快完成了。让我们启动一个 notebook 来测试 XGBoost。直接导入会报错。为了避免它,我们必须将 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!
我们都准备好了!
回答by Andrey Ilin
Look here https://github.com/Rafi993/xgboost/for building xgboost on your machine. 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.
Then run the following commands in cmd in order to install python bindings:
cd python-package python setup.py install
You might also need a proper mingw (google for tdm-gcc) and the latest setuptools from anaconda.
看这里https://github.com/Rafi993/xgboost/在你的机器上构建 xgboost。上面的解决方案有很多不同的变体,但似乎上面链接中的版本是好的。至少这对我有用:我已经在 Windows 7 和 Windows Server 2008 上对其进行了测试。
然后在 cmd 中运行以下命令以安装 python 绑定:
cd python-package python setup.py install
您可能还需要一个合适的 mingw(tdm-gcc 的谷歌)和来自 anaconda 的最新安装工具。
I hope it will help
我希望它会有所帮助
回答by Puneet Sinha
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. You should see something like "fatal error: no input file"
打开 Windows 命令提示符并键入 gcc。您应该会看到类似“致命错误:没有输入文件”的内容
Next type make. You should see something like "No targets specified and no makefile found"
下一个类型make。您应该会看到类似“未指定目标且未找到 makefile”之类的内容
Type git. If you don't have git, install it and add it to your PATH. These should be all the tools you need to build the xgboost project. To get the source code run these lines:
输入 git。如果您没有 git,请安装它并将其添加到您的 PATH。这些应该是构建 xgboost 项目所需的所有工具。要获取源代码,请运行以下几行:
- cd c:\
- git clone --recursive https://github.com/dmlc/xgboost
- cd xgboost
- git submodule init
- git submodule update
- cp make/mingw64.mk config.mk
- make -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.
- CDC:\
- git clone --recursive https://github.com/dmlc/xgboost
- cd xgboost
- git子模块初始化
- git子模块更新
- cp make/mingw64.mk config.mk
- make -j4 请注意,我从 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 包,请执行以下操作:
- cd python-package
python setup.py install Now you should be good to go. Open up Python, and you can import the package with:
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.
- cd python 包
python setup.py install 现在你应该可以开始了。打开 Python,您可以使用以下命令导入包:
import xgboost as xgb 为了测试安装,我继续运行了包含在项目的 demo/guide-python 文件夹中的 basic_walkthrough.py 文件,没有出现任何错误。
回答by Bruce Gai
You can download the xgboost package to your local computer, and you better place the xgboost source file under D:\ or C:\ (ps: download address: http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost, and select "xgboost-0.6-cp35-cp35m-win_amd64.whl",but it is up to your operation system), and you open the Anaconda prompt, type in pip install D:\xgboost-0.6-cp35-cp35m-win_amd64.whl
, then you can successful install xgboost into your anaconda
可以将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中
回答by stidmatt
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.
这为我解决了问题,没有任何问题。
回答by Shu Zhang
- Download package from this website.
I downloaded
xgboost-0.6-cp36-cp36m-win_amd64.whl
for anaconda 3 (python 3.6) - Put the package in directory
C:\
- Open anaconda 3 prompt
- Type
cd C:\
- Type
pip install C:\xgboost-0.6-cp36-cp36m-win_amd64.whl
- Type
conda update scikit-learn
- 从这个网站下载包。我下载
xgboost-0.6-cp36-cp36m-win_amd64.whl
了 anaconda 3 (python 3.6) - 将包放入目录
C:\
- 打开 anaconda 3 提示
- 类型
cd C:\
- 类型
pip install C:\xgboost-0.6-cp36-cp36m-win_amd64.whl
- 类型
conda update scikit-learn
回答by Regi Mathew
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
回答by Renu
I figured out easy way to install XgBoost by mix of what is mentioned here.
我找到了通过混合使用这里提到的内容来安装 XgBoost 的简单方法。
Step 1: Install gitbash from hereand 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'
第四步: alias make='mingw32-make'
step 5: cp make/mingw64.mk config.mk; make -j4
第 5 步: 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 的路径。