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

1
  • If you find it really hard to install it on Windows, you could import in Colab and use it there.
    – Suraj
    May 13, 2020 at 10:37

9 Answers 9

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.

4
  • 3
    Just a quick hint: Issue the command in the Anaconda Promt, running at Administrator. Otherwise it didn't work for me. Mar 8, 2018 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. Mar 8, 2018 at 12:50
  • @CGFoX 1. Make sure you have the correct conda environment activated. 2. conda list should show the install, you didn't use pip to install the dependency if you used the command I provided Apr 26, 2018 at 4: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, 2019 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

2
  • 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, 2016 at 7:12
  • I get WindowsError: [Error 193] %1 is not a valid Win32 application when I try to import xgboost Nov 27, 2016 at 0: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

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

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.

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.

1
  • 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? Nov 13, 2019 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.