Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named xgboost

When I tried import from python terminal I get this error, although I followed all the steps to install xgboost, somehow python is unable to get the package details.I am relatively new to python, I could easily install numpy and pandas packages,I used this link for installation on MACOSX http://xgboost.readthedocs.io/en/latest/build.html

>>> import xgboost
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   ImportError: No module named xgboost

When I did pip install xgboost, I am getting this error,

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/h7/pyph_7qj6171tqp50cf2xc7m0000gn/T/pip-build-TEvbD6/xgboost/ 

I am getting this on printing sys path,

print sys.path

['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

like image 546
miniQ Avatar asked Nov 22 '16 17:11

miniQ


4 Answers

First you need to get control of your python environment. Download the homebrew python by pasting these into a fresh terminal window

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

here you will be prompterd to enter your password. After homebrew is installed, install python with brew install python. Please check your installation with brew doctor and follow homebrew's suggestions.

Now, with a fresh terminal window, install xgboost from pip. Open terminal and paste this in:

pip install xgboost
like image 109
kilojoules Avatar answered Oct 24 '22 22:10

kilojoules


I had the same issue. I tried everything but the only solution that worked for me to was to install the whl file directly from here : http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost

then you can do :

pip install yourFile.whl

On windows I managed to just double click on the whl file and install it

Good luck

like image 37
Mohamed AL ANI Avatar answered Oct 24 '22 22:10

Mohamed AL ANI


FYI if you are using anaconda dist'n then need to do

conda install -c conda-forge xgboost
like image 10
Meng Zhao Avatar answered Oct 25 '22 00:10

Meng Zhao


Use conda install in Anaconda Powershell Prompt then use pip install

conda install -c conda-forge xgboost
pip install xgboost
like image 10
E.Zolduoarrati Avatar answered Oct 24 '22 23:10

E.Zolduoarrati