sfhotmail sfhotmail - 6 months ago 146
Python Question

Xgboost work on pycharm but not in Jupyter NoteBook

I've successfully installed Xgboost in windows with Pycharm Python, and it is working.
However, in Jupyter NoteBook, it is not working.

import xgboost as xgb
---> 12 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'

In Jupyter the xgboost package is at:

> !pip install xgboost

Requirement already satisfied: xgboost in c:\users\sifangyou\anaconda3\lib\site-packages\xgboost-0.6-py3.6.egg

Requirement already satisfied: numpy in c:\users\sifangyou\anaconda3\lib\site-packages (from xgboost)

Requirement already satisfied: scipy in c:\users\sifangyou\anaconda3\lib\site-packages (from xgboost)

However, my xgboost is installed in:

How can I direct Jupyter to the correct xgboost package location?

Answer Source

Ideally, you should install packages in the location in your PYTHONPATH (which is where python looks). Usually pip does this, however its possible that jupyter, and pycharm are using different version. Try:

import sys
print sys.executable


import os
print os.environ['PYTHONPATH'].split(os.pathsep)

in both pycharm and jupyter.

You can then try one of two things:

  1. install the package with the right version of pip:

    /path/to/python /path/to/pip install PackageName

  2. dynamically hacking your python path in python:


 import sys
 import xgboost

Whether 2 works depends on what magic happens when xgboost is installed. (Its possible that it may not by usable without running the install steps).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download