如何在Jupyter Notebook和终端之间匹配python版本的版本? 3.6.5至3.7

时间:2018-10-14 20:30:11

标签: python jupyter-notebook

我在jupyter笔记本电脑上遇到以下错误,我认为这是由于笔记本电脑上有多个python版本,我正在尝试导入xgboost

from xgboost import XGBClassifier

出现以下错误,

--------------------------------------------------------------------------- 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'

,当我运行kfold选择时,我还会收到以下警告,

# 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)

我检查了终端和jupyter笔记本上的python版本,发现jupyter笔记本具有3.6.5版本,终端具有3.7版本。

不确定是不是引起问题的原因。

enter image description here

enter image description here

jupyter笔记本:

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']

这个问题不仅与xgboost软件包有关,而且在我尝试导入keras时也会发生

1 个答案:

答案 0 :(得分:0)

首先,您需要为Python 3.7安装Jupyter。如您所见,当您在控制台中运行python3时,Python 3.7附带了该命令,这就是您要使用的命令。

安装Jupyter
Here is the documentation for reference. 根据文档,您只需运行:

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

在Python 3.7上运行Jupyter
python3 -m pip install jupyter
将运行Jupyter,但特别是在python3上运行,它已与Python 3.7绑定。

*这是我记得这样做的方式,但我现在尚未对其进行测试,因此,如果发生了某些更改,则可能无法正常工作。