Python – ImportError: No module named xgboost

jupyter-notebookpython

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']

Best Answer

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