31
votes

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

11
Well, the module is there but there is no such class. Maybe it's in a submodule? e.g. from xgboost.xgbclassifier import XGBClassifierlucasnadalutti
You didn't name your local file xgboost.py, did you?John Gordon
ImportError: No module named 'xgboost.xgbclassifier', I tried using your command, it returned this.miniQ
@JohnGordon no! Running it on jupyter notebook, name of the file is different. I am new to python, I need the classifier to be importedminiQ
If you can't even import xgboost, then the installation must have gone wrong. What directory did you install it in?John Gordon

11 Answers

23
votes

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
12
votes

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

8
votes
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
sudo cp make/minimum.mk ./config.mk;
sudo make -j4;
sh build.sh
cd python-package
python setup.py install

Atleast Now I can import xgboost from terminal on macosx, I haven't been able to import it in jupyter notebook as yet.

7
votes

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

conda install -c conda-forge xgboost
7
votes

Use conda install in Anaconda Powershell Prompt then use pip install

conda install -c conda-forge xgboost
pip install xgboost
5
votes

Try running

pip install xgboost

in Anaconda prompt; it's important that you do it in Anaconda prompt so it is in same location as the Python you're using.

3
votes

Write this on the terminal of Jupyter:

conda install -c anaconda py-xgboost
1
votes

On Pycharm you can go to Pycharm > Prefernces, go to the interpreter you have and install the xgboost package.

1
votes

I tried

pip install xgboost

and

pip3 install xgboost

But it doesn't work

ModuleNotFoundError: No module named 'xgboost'

Finally I solved Try this in the Jupyter Notebook cell

import sys
!{sys.executable} -m pip install xgboost

Results:

Collecting xgboost
  Using cached xgboost-1.4.1-py3-none-win_amd64.whl (97.8 MB)
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1
0
votes
  1. Open the terminal
  2. Type pip install xgboost and hit enter.

Make sure your internet connection is good.

Do not forget to crosscheck the successful installation of it in jupyter.

0
votes

Give the following commands a try.

pip install xgboost
pip install plotly