Jupyter notebook xgboost import

Running a shell escape !pip3 doesn't guarantee that it will install in the kernel you are running. Try:

import sys
print(sys.base_prefix)

and see if this matches either of your terminal pythons. You should be able to run <base_prefix>/bin/pip install <package> to ensure it is in the right site-packages.

You can also look at which python your kernel is running by looking in kernel.json most likely in ~/Library/Jupyter/kernels/<kernel>/kernel.json.

Note: you can also programmatically install packages with:

import pip
pip.main(['install', '<package>'])

which will force it to be in the right site-packages for your kernel.


Within Jupyter Notebook cell, try running:

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

This allows the package to be install with right on Jupiter notebook


if you are using anaconda, you can install XGBoost with a command that mentioned below :

conda install -c conda-forge xgboost