Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter notebook xgboost import

I have the problem below (I'm on a MAC)

I can import xgboost from python2.7 or python3.6 with my Terminal but the thing is that I can not import it on my Jupyter notebook.

import xgboost as xgb

ModuleNotFoundError Traceback (most recent call last) in () ----> 1 import xgboost as xgb

ModuleNotFoundError: No module named 'xgboost'

Although I write :

!pip3 install xgboost

It prints that :

Requirement already satisfied: xgboost in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost) Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from xgboost)

Help please I searched everywhere :(

like image 613
FFL75 Avatar asked Jun 30 '17 23:06

FFL75


People also ask

How do I download Xgboost in Jupyter notebook?

Installing xgboost in AnacondaStep 1: Install the current version of Python3 in Anaconda. Step 2: Check pip3 and python3 are correctly installed in the system. Step 3: To install xgboost library we will run the following commands in conda environment.

How do I import Xgboost into Python?

As usual, you start by importing the library xgboost and other important libraries that you will be using for building the model. Note you can install python libraries like xgboost on your system using pip install xgboost on cmd. Separate the target variable and rest of the variables using . iloc to subset the data.


1 Answers

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.

like image 159
AChampion Avatar answered Oct 13 '22 12:10

AChampion