ImportError: No module named xgboost
Question:
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’]
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
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.
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
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.
FYI if you are using anaconda dist’n then need to do
conda install -c conda-forge xgboost
Write this on the terminal of Jupyter:
conda install -c anaconda py-xgboost
On Pycharm you can go to Pycharm > Prefernces, go to the interpreter you have and install the xgboost
package.
Use conda install in Anaconda Powershell Prompt then use pip install
conda install -c conda-forge xgboost
pip install xgboost
- Open the terminal
- 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.
Give the following commands a try.
pip install xgboost
pip install plotly
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:programdataanaconda3libsite-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:programdataanaconda3libsite-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1
All you need within Jupyter Notebook cell is:
try running
import sys
!{sys.executable} -m pip install xgboost
if you run
pip install xgboost
in command line and no result, run the same command in jupyter notebook.
for ubuntu 18 LTS, this worked for me.
cmake is a pre-requiste to it, so if you havent you would need to install that, currently at print its version 3.10 + minimum.
in terminal:
sudo snap install cmake –classic
in jupyter notebook(if terminal just edit it)
import sys
!{sys.executable} -m pip install xgboost
In my case, I had multiple Python versions, and I was installing it in the wrong one.
pip install xgboost
installed the module on Python 3.7, but I needed to install it with Python 3.10. What I run was:
py -m pip install xgboost
which worked, since "py" is my binary for Python 3.10. The suitable command if you have multiple Python versions may be different depending on which version you have. In Ubuntu, for example, this worked for me:
python3.8 -m pip3 install 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’]
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
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.
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
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.
FYI if you are using anaconda dist’n then need to do
conda install -c conda-forge xgboost
Write this on the terminal of Jupyter:
conda install -c anaconda py-xgboost
On Pycharm you can go to Pycharm > Prefernces, go to the interpreter you have and install the xgboost
package.
Use conda install in Anaconda Powershell Prompt then use pip install
conda install -c conda-forge xgboost
pip install xgboost
- Open the terminal
- 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.
Give the following commands a try.
pip install xgboost
pip install plotly
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:programdataanaconda3libsite-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:programdataanaconda3libsite-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1
All you need within Jupyter Notebook cell is:
try running
import sys
!{sys.executable} -m pip install xgboost
if you run
pip install xgboost
in command line and no result, run the same command in jupyter notebook.
for ubuntu 18 LTS, this worked for me.
cmake is a pre-requiste to it, so if you havent you would need to install that, currently at print its version 3.10 + minimum.
in terminal:
sudo snap install cmake –classic
in jupyter notebook(if terminal just edit it)
import sys
!{sys.executable} -m pip install xgboost
In my case, I had multiple Python versions, and I was installing it in the wrong one.
pip install xgboost
installed the module on Python 3.7, but I needed to install it with Python 3.10. What I run was:
py -m pip install xgboost
which worked, since "py" is my binary for Python 3.10. The suitable command if you have multiple Python versions may be different depending on which version you have. In Ubuntu, for example, this worked for me:
python3.8 -m pip3 install xgboost