1

I face the following errors on jupyter notebook which I believe is due to because of multiple versions of python on my laptop, I am trying import xgboost

from xgboost import XGBClassifier

I get the following error,

--------------------------------------------------------------------------- ModuleNotFoundError                       Traceback (most recent call last) <ipython-input-4-3728958e329a> in <module>
     15 from sklearn.svm import SVC
     16 from sklearn.neural_network import MLPClassifier
---> 17 from xgboost import XGBClassifier

ModuleNotFoundError: No module named 'xgboost'

and I also get the following warnings when I run the kfold selection,

# evaluate each model in turn
for name, model in models:
    kfold = model_selection.KFold(n_splits=10, random_state=seed)
    cv_results = model_selection.cross_val_score(
        model, X_train, Y_train, cv=kfold, scoring=scoring)
    results.append(cv_results)

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)

I checked the versions of python on my terminal and jupyter notebook, I see that jupyter notebook has 3.6.5 version and terminal has 3.7 version.

Not sure if this is what causing the issue.

enter image description here

enter image description here

jupyter notebook:

import sys
print(sys.version)
print(sys.path)
3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/extensions', '/Users/shafeeqrahaman/.ipython']

This issue is not just with xgboost package but happens when I try to import keras as well

2
  • If you are installing you packages using pip, you can do pip3.6 install xgboost, so the package gets installed in the Jupyter notebook version. Commented Oct 14, 2018 at 20:33
  • how can I upgrade notebook to 3.7 Commented Oct 14, 2018 at 20:34

1 Answer 1

2

First you need to install Jupyter for Python 3.7. As you can see when you run python3 in the console it comes up with Python 3.7 so that's the command you want to be using.

Installing Jupyter
Here is the documentation for reference. According to the documentation you simply just run:

python3 -m pip --upgrade pip
python3 -m pip install jupyter

Running Jupyter on Python 3.7
python3 -m pip install jupyter
Will run Jupyter, but specifically on python3, which is bound to Python 3.7 for you.

*This is how I remember doing it but I haven't tested it right now so if something has changed this may not work.

Sign up to request clarification or add additional context in comments.

5 Comments

I followed the commands but still on the jupyter notebook it says 3.6.5, import sys print(sys.base_prefix) /Library/Frameworks/Python.framework/Versions/3.6
import sys print(sys.version) 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55)
if you have both python 3.6 and python 3.7 installed, the version that python3 invokes will depend on your specific configuration. Since python3 points to either the python3.6 or python3.7 executable, you may need to specify python3.7 -m pip install on such a system to guarantee the 3.7 interpreter is invoked.
@CoreyGoldberg I tried that but the python version on the jupyter notebook points to 3.6.5, I would like to know what can I do to make python in jupyter notebook point to 3.7.0
import sys print(sys.version) 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03:03:55) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.