如何在jupyter笔记本和终端之间匹配python版本?3.6.5至3.7

2024-05-23 16:33:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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选择时,也会收到以下警告

^{pr2}$

我检查了我的终端和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时也会发生


Tags: fromimport版本lib错误syslibrary笔记本
1条回答
网友
1楼 · 发布于 2024-05-23 16:33:15

首先需要安装Jupyter for python3.7。正如您在控制台中运行python3时所看到的,它会出现python3.7,因此这是您想要使用的命令。

安装Jupyter
Here is the documentation for reference. 根据您刚刚运行的文档:

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

在Python3.7上运行Jupyter python3 -m pip install jupyter
将运行Jupyter,但特别是在python3上,它为您绑定到了python3.7。在

*我记得是这样做的,但我现在还没有测试过,所以如果有什么改变了,这可能行不通。在

相关问题 更多 >