Fix "No module named xgboost" ImportError in Jupyter Notebook

Fix "No module named xgboost" ImportError in Jupyter Notebook

XGBoost is gaining a lot of traction, and its downloads are increasing. Yet, there's a common issue with the installation, especially in Jupyter Notebook environments where it's typically installed with:

! pip install xgboost
# Or
! pip3 install xgboost
# Or
! conda install -c conda-forge xgboost

Oftentimes, even though this approach works for other modules, this will result in:

ImportError: No module named xgboost

This issue especially seems to be present in Jupyter Notebooks - the most common environment in which you might use XGBoost. This issue may be fixed by using Python's pip module explicitly:

Get free courses, guided projects, and more

No spam ever. Unsubscribe anytime. Read our Privacy Policy.

! python -m pip install xgboost
# Or
! python3 -m pip install xgboost

But as it may also fail, one of the most common fixes is:

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

After which, you can import without issues:

import xgboost
Last Updated: July 1st, 2022
Was this helpful?
David LandupAuthor

Entrepreneur, Software and Machine Learning Engineer, with a deep fascination towards the application of Computation and Deep Learning in Life Sciences (Bioinformatics, Drug Discovery, Genomics), Neuroscience (Computational Neuroscience), robotics and BCIs.

Great passion for accessible education and promotion of reason, science, humanism, and progress.

Project

Real-Time Road Sign Detection with YOLOv5

# python# machine learning# computer vision# pytorch

If you drive - there's a chance you enjoy cruising down the road. A responsible driver pays attention to the road signs, and adjusts their...

David Landup
David Landup
Details
Project

Image Captioning with CNNs and Transformers with Keras

# python# artificial intelligence# machine learning# tensorflow

In 1974, Ray Kurzweil's company developed the "Kurzweil Reading Machine" - an omni-font OCR machine used to read text out loud. This machine...

David Landup
David Landup
Details

© 2013-2022 Stack Abuse. All rights reserved.

DisclosurePrivacyTerms