Reputation: 45
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: C:\Users\sifangyou\xgboost\python-package
How can I direct Jupyter to the correct xgboost package location?
Upvotes: 1
Views: 1787
Reputation: 15810
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
and
import os
print os.environ['PYTHONPATH'].split(os.pathsep)
in both pycharm and jupyter.
You can then try one of two things:
install the package with the right version of pip:
/path/to/python /path/to/pip install PackageName
dynamically hacking your python path in python:
:
import sys
sys.path.append(r"C:\Users\sifangyou\xgboost\python-package")
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).
Upvotes: 2