14

I tried to install XGBoost package in python. I am using windows os, 64bits . I have gone through following.

The package directory states that xgboost is unstable for windows and is disabled: pip installation on windows is currently disabled for further invesigation, please install from github. https://pypi.python.org/pypi/xgboost/

I am not well versed in Visual Studio, facing problem building XGBoost. I am missing opportunities to utilize xgboost package in data science.

Please guide, so that I can import the XGBoost package in python.

Thanks

Hack-R
  • 22,422
  • 14
  • 75
  • 131
shan
  • 553
  • 2
  • 9
  • 25
  • If you find it really hard to install it on Windows, you could import in Colab and use it there. – Suraj May 13 '20 at 10:37

9 Answers9

23

If you are using anaconda (or miniconda) you can use the following:

Check install by:

  • Activating the environment (see below)
  • Running conda list

To activate an environment:

On Windows, in your Anaconda Prompt, run (assumes your environment is named myenv):

  • activate myenv

On macOS and Linux, in your Terminal Window, run (assumes your environment is named myenv):

  • source activate myenv

Conda prepends the path name myenv onto your system command.

Adrian Torrie
  • 2,795
  • 3
  • 40
  • 61
  • 3
    Just a quick hint: Issue the command in the Anaconda Promt, running at Administrator. Otherwise it didn't work for me. – stefanbschneider Mar 08 '18 at 12:46
  • While the installation with anaconda succeeds, xgboost still doesn't show up in `pip list` and I get an error when trying to import it. – stefanbschneider Mar 08 '18 at 12:50
  • @CGFoX 1. Make sure you have the [correct conda environment activated](https://conda.io/docs/user-guide/tasks/manage-environments.html#activating-an-environment). 2. [`conda list`](https://conda.io/docs/commands/conda-list.html) should show the install, you didn't use pip to install the dependency if you used the command I provided – Adrian Torrie Apr 26 '18 at 04:10
  • There is no XGBoost package for Windows on conda-forge. It is only available for Linux and OSX. The above command will not find any package when run on a windows environment. So why is this answer here, and upvoted so much? – erotavlas Sep 18 '19 at 16:53
9

Build it from here:

  • download xgboost whl file from here (make sure to match your python version and system architecture, e.g. "xgboost-0.6-cp35-cp35m-win_amd64.whl" for python 3.5 on 64-bit machine)
  • open command prompt
  • cd to your Downloads folder (or wherever you saved the whl file) pip install xgboost-0.6-cp35-cp35m-win_amd64.whl (or whatever your whl file is named)
5

You first need to build the library through "make", then you can install using anaconda prompt (if you want it on anaconda) or git bash (if you use it in Python only).

First follow the official guide with the following procedure (in Git Bash on Windows):

git clone --recursive https://github.com/dmlc/xgboost
git submodule init
git submodule update

then install TDM-GCC here and do the following in Git Bash:

alias make='mingw32-make'
cp make/mingw64.mk config.mk; make -j4

Last, do the following using anaconda prompt or Git Bash:

cd xgboost\python-package  
python setup.py install 

Also refer to these great resources:

Official Guide

Installing Xgboost on Windows

Installing XGBoost For Anaconda on Windows

George Liu
  • 3,601
  • 10
  • 43
  • 69
  • Thanks a lot. I have followed your pointed resources and installed xgboost in windows. However, I am facing a problem, when I ran the following lines to get cv parameters: – shan May 29 '16 at 07:12
  • I get WindowsError: [Error 193] %1 is not a valid Win32 application when I try to import xgboost – John Constantine Nov 27 '16 at 00:05
2

You can pip install catboost. It is a recently open-sourced gradient boosting library, which is in most cases more accurate and faster than XGBoost, and it has categorical features support. Here is the site of the library: https://catboost.ai

2

pip install xgboost works also with python 3.8, whereas other options mentioned above did not work for me

STA
  • 30,729
  • 8
  • 45
  • 59
1

The following command should work but, If you have a problem with this command

conda install -c conda-forge xgboost

First activate your environment . Assume your environment is named simply write in conda terminal :

activate <MY_ENV>

and then

 pip install xgboost
1

on a macOS the following command worked conda install -c conda-forge xgboost but before doing this i had read some other article and hence did install gcc using brew

Vivek
  • 161
  • 3
0

Besides what's already on developers' github, which is building from source(creating a c++ environment, etc.), I have found an easier way to do it, which I explained here with details. Basically, you have to go a website by UC Irvine and download a .whl file, then cd to the folder and install xgboost with pip.

Roozbeh Bakhshi
  • 830
  • 1
  • 8
  • 9
0

XGBoost is used in Applied Machine Learning and is known for its gradient boost algorithm and it is available as a library in python but has to be compiled using cmake.

Alternatively what you can do is from this link you can download the C pre-compiled library and install it using the pip install < FILE-NAME.whl> command. Ensure you have downloaded the library which is compatible with your python version.

I experienced this problem while I was using the same in Anaconda(Spyder). Then just restart the kernel and your error will go away.

Sambhav Kumar
  • 368
  • 3
  • 19
  • From Review: Hi, while links are great way of sharing knowledge, they won't really answer the question if they get broken in the future. Add to your answer the essential content of the link which answers the question. In case the content is too complex or too big to fit here, describe the general idea of the proposed solution. Remember to always keep a link reference to the original solution's website. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – sɐunıɔןɐqɐp Nov 13 '19 at 11:51