vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

文章目录

*
1 插件安装
2 相关python库安装

+ 2.1 python版本问题
+ 2.2 开始安装库包
+ 2.3 解决Failed to start the Kernel问题
3 配置成功

1 插件安装

想要在vscode中使用jupyter,首先我们需要在vscode中安装插件 Jupyter

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
在拓展中搜索jupyter直接安装即可。

; 2 相关python库安装

在安装插件之后,一整个安装过程才算是刚刚开始,最重要的步骤还是安装相应python库,在这个过程中会遇到很多棘手的问题。

2.1 python版本问题

在安装相关python库之前,必须强调一下python的版本问题,避免到最后因为版本不适配导致做无用功,只能从头来过。在安装相应python库的过程中我们需要安装名为 pyzmq的库,因为 pyzmq的版本限制(这个后续会解释),我们不能安装大于3.9的python版本, pyzmq对python版本要求如下。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

经过我的验证 python=3.9是可行,但是如果使用 python=3.10就会出现报错,具体错误如下所示。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
这里的报错也显示,不是因为 pip安装的问题,而是包本身的问题导致安装失败,这其实就是因为 python==3.10以上的版本不支持 pyzmq==19.0.2。因此我们在选择python版本时,最高只能选择 python==3.9

; 2.2 开始安装库包

现在如果直接建立一个jupyter文件 *.ipynb然后直接在vscode中运行,会直接告诉你没有安装 ipykernel包。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

忽略 python 3.10.4就好,这里为了给大家演示高版本python不能够使用,就直接创建了一个 python=3.10的环境。

这里如果点击 Install就会显示以下信息。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
这里边给了安装命令,但是我不推荐使用 conda进行安装,我们可以执行下面的命令进行安装。
pip install jupyter -i https://pypi.tuna.tsinghua.edu.cn/simple

命令中的-i https://pypi.tuna.tsinghua.edu.cn/simple是为了使用国内源,这样下载速度会得到明显提高

执行完命令后,会得到以下的结果,成功安装了一系列的包,这个时候所有使用到的包都已经安装成功。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
这个时候当你觉得已经安装成功兴致勃勃的打开vscode准备使用jupyter的时候,vscode会给你当头一棒,没错,你会得到一个error。
vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

2.3 解决Failed to start the Kernel问题

出现这种情况是因为 pyzmq==23.2.1的版本过高,最直接的办法就是我们还用低版本的 pyzmq就好,这里我们使用 pyzmq==19.0.2。这里就是为什么我们不能使用大于3.9版本的python,其实 pyzmq==23.2.1是能够在 python==3.9的环境中运行的,但是因为使用过高版本的 pyzmq会出现 Failed to start the Kernel.的错误,所以我们只能 pythonpyzmq都使用较低版本。

我们使用命令

pip uninstall pyzmq
pip install pyzmq==19.0.2

卸载已经安装的较高版本的 pyzmq,然后安装 pyzmq==19.0.2

执行完上述命令之后,会出现报错

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

报错中提示到 jupyter-client需要的 pyzmq>23.0但是我们安装的版本太低。那么接下来就需要降低 jupyter-client的版本,我们先将它卸载,然后重新安装 jupyter-client==6.1.12

pip uninstall jupyter-client
pip install jupyter-client==6.1.12

注意!!!执行上述命令的时候,卸载 jupyter-client后重新安装的时候必须加上版本号,不然会默认安装最新版本的,然后最新版本的 jupyter-client需要较高版本的 pyzmq,所以会默认将先前安装的低版本 pyzmq卸载掉,重新安装高版本的依赖。运行结果下所示。

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

这样安装的话,我们对 pyzmq将版本的操作就做了无用功,需要重新执行。

执行命令 pip install jupyter-client==6.1.12后,会出现报错

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
报错中提到 jupyter-console需要 jupyter-client>=7.0,我们安装版本过低。因此我们需要对 jupyter-console也做降版本处理。
pip uninstall jupyter-console
pip install jupyter-console==6.4.0

当然也要注意,重新安装低版本 jupyter-console时需要加上低版本的版本号!

执行上述命令后,终端会显示

vscode中配置jupyter(彻底解决Failed to start the Kernel问题)
这里没有出现报错,说明所有包的版本都已经兼容了。

3 配置成功

执行完上述所有操作以后,vscode中的jupyter就已经成功配置了,接下来就可以打开vscode选择配置好的环境使用本地的jupyter notebook了。

Original: https://blog.csdn.net/weixin_52096278/article/details/126568679
Author: cporin
Title: vscode中配置jupyter(彻底解决Failed to start the Kernel问题)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/668564/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球