The Reason for modulenotfounderror: no module named ‘xgboost’ is either xgboost is not installed or misconfigured in the system. The best way to fix this error is to reinstall this xgboost python module. Since most of the Machine Learning Algorithm come in a bundle all together for example scikit-learn. But that is not the case with XGBOOST. For this package, we need to externally install this.
In this article, we will understand the best and quick ways to install the xgboost module. We will also explore a bit on XGBOOST importance and brief usages to give you the complete depth of this error.
modulenotfounderror: no module named ‘xgboost’ ( Cause and Fix ) –
As we have already discussed that the installation of XGBOOST is the best solution so let’s see with real code and command in this section.
Solution 1: Using pip package manager –
pip is the easiest and best way to install this XGBOOST module. Here is the command for installation (pip should be in the system )
pip install xgboost
Solution 2: Using Anaconda to install XGBOOST –
Just like pip, The Anaconda distribution for scientific python libraries is quite convenient. Under Anaconda there is conda package manager ( similar to pip ). Under the same, Please use the below command to install XGBOOST.
conda install -c conda-forge xgboost
Solution 3: Using source code setup file –
This is the longest path but it gives a deeper version for XGBOOST. Let me make you understand with one small scenario, Suppose there is a fix in the XGBOOST package dev branch but unfortunately it is not officially moved to master or any stable branch. In this case above two methods will not be sufficient. You have to go with this path.
git clone --recursive https://github.com/dmlc/xgboost git submodule init git submodule update alias make='mingw32-make' cp make/mingw64.mk config.mk; make -j4 cd xgboost\python-package python setup.py install
Solution 4 : Using Whl file –
pip install downloaded.whl
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.