How to install xgboost package in python (windows platform)?

Solution 1:

In case anyone's looking for a simpler solution that doesn't require compiling it yourself:

  1. 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)
  2. open command prompt
  3. cd to your Downloads folder (or wherever you saved the whl file)
  4. pip install xgboost-0.6-cp35-cp35m-win_amd64.whl (or whatever your whl file is named)

If you find it won't install because of a missing dependency, download and install the dependency first and retry.

If it complains about access permissions, try opening your command prompt as Administrator and retry.

This gives you xgboost and the scikit-learn wrapper, and saves you from having to go through the pain of compiling it yourself. :)

Solution 2:

Note that as of the most recent release the Microsoft Visual Studio instructions no longer seem to apply as this link returns a 404 error:

https://github.com/dmlc/xgboost/tree/master/windows

You can read more about the removal of the MSVC build from Tianqi Chen's comment here.

So here's what I did to finish a 64-bit build on Windows:

  1. Download and install MinGW-64: http://sourceforge.net/projects/mingw-w64/
  2. On the first screen of the install prompt make sure you set the Architecture to x86_64 and the Threads to win32
  3. 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
  4. 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
  5. Open a Windows command prompt and type gcc. You should see something like "fatal error: no input file"
  6. Next type make. You should see something like "No targets specified and no makefile found"
  7. 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:

  1. cd c:\
  2. git clone --recursive https://github.com/dmlc/xgboost
  3. cd xgboost
  4. git submodule init
  5. git submodule update
  6. cp make/mingw64.mk config.mk
  7. 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.

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:

  1. cd python-package
  2. 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.

Solution 3:

I installed XGBoost successfully in Windows 8 64bit, Python 2.7 with Visual Studio 2013 (don't need mingw64)

Updated 15/02/2017

With newer version of XGBoost, here are my steps

Step 1. Install cmake https://cmake.org/download/

Verify cmake have been installed successfully

$ cmake
Usage

cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
...

Step 2. Clone xgboost source

$ git clone https://github.com/dmlc/xgboost xgboost_dir

Step 3. Create Visual Studio Project

$ cd xgboost_dir
$ mkdir build
$ cd build
$ cmake .. -G"Visual Studio 12 2013 Win64"

Step 4. Build Visual Studio 2013 project

  • Open file xgboost_dir/build/ALL_BUILD.vcxproj with Visual Studio 2013
  • In Visual Studio 2013, open BUILD > Configuration Manager...
    • choose Release in Active solution configuration
    • choose x64 in Active solution platform
  • Click BUILD > Build Solution (Ctrl + Shift +B)

After build solution, two new files libxgboost.dll and xgboost.exe are created in folder xgboost_dir/lib

Step 5. Build python package

  • Copy file libxgboost.dll to xgboost_dir/python-package
  • Change directory to xgboost_dir/python-package folder
  • Run command python setup.py install

Verify xgboost have been installed successfully

$ python -c "import xgboost"

Old Answer

Here are my steps:

  1. git clone https://github.com/dmlc/xgboost
  2. git checkout 9bc3d16
  3. Open project in xgboost/windows with Visual Studio 2013
  4. In Visual Studio 2013, open BUILD > Configuration Manager...,
    • choose Release in Active solution configuration
    • choose x64 in Active solution platform
  5. Rebuild xgboost, xgboost_wrapper
  6. Copy all file in xgboost/windows/x64/Release folder to xgboost/wrapper
  7. Go to xgboost/python-package, run command python setup.py install
  8. Check xgboost by running command python -c "import xgboost"

Solution 4:

I just installed xgboost both for my python 2.7 and python 3.5, anaconda, 64bit machine and 64 bit python.

both VERY simple, NO VS2013 or git required.

I think it works for normal python, too.

If you use python 3.5:

1: download the package here, the version depends on your python version, python3.5 or python 3.6, 32bit or 64bit.

2: use the command window, use cd to make the download folder as your pwd, then use

pip install filename.whl

OK, finished. For more detailed steps, see this answer

if you use python 2.7, you do NOT need to download the VS2013 to build it yourself, because I have built it, you can download the file I built and install it directly

1: Download it here by google drive

2: Download it, decompress it, paste it here:

"your python path\Lib\site-packages"

Then you should have something look like this:

enter image description here

3: In python-package folder showed above, use cmd window, cd there and run

python setup.py install 

use this code

 import xgboost 

in your python to check whether you have installed mingw-64 or not, No error information means you have installed the mingw-64 and you are finished.

If there are error information

"WindowsError: [Error 126] "

That means you have not installed mingw-64, and you have one more step to go.

Download the mingw-64 here: http://sourceforge.net/projects/mingw-w64/

Choose x86_64 instead of the default "i686" when you installed the mingw-64, then add "your install path\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin;" to your PATH, it should be something like this:

"C:\Program Files\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin;"

(this is mine).

Don't forget the ";" in the PATH.

Then you are finished,you can use

import xgboost 

in your python to check that, Yeah!

PS: if you don't know how to add path, just google it to get solutions. Don't worry, it's very simple.

Solution 5:

If You are installing XGBoost for a particular Project and You are using Pycahrm then you need to follow the procedures given below:

  1. Download xgboost‑0.72‑cp36‑cp36m‑win_amd64.whl from Here (as I am using Python 3.6 if you use different version of Python like 2.7 then you need to install xgboost‑0.72‑cp27‑cp27m‑win_amd64.whl).

  2. Copy the to your Project Interpreter directory. You can find the directory of Project Interpreter by clicking File -> Settings -> Project Interpreter from Pycharm.

  3. Open Command Prompt. Go to directory to you Project Interpreter from cmd. Write the following command: pip install xgboost-0.72-cp36-cp36m-win_amd64.whl