简体   繁体   English

Python VS 代码未连接 IPython kernel

[英]Python VS code does not connect with IPython kernel

I have created a new virtual env and trying to connect with the VS code.我创建了一个新的虚拟环境并尝试连接 VS 代码。 When I open the folder in VS code that contains the file and virtual env, on the left bottom side I can see the python interperator selected as shown in the following figure:当我在 VS 代码中打开包含文件和虚拟环境的文件夹时,在左下角我可以看到选择的 python interperator,如下图所示:

在此处输入图像描述

However, when I run the program, it shows the message that it is connecting to IPython Kernel as shown in the following picutre但是,当我运行该程序时,它显示正在连接到 IPython Kernel 的消息,如下图所示

在此处输入图像描述

However, after some time it throws an error message that "unable to start session for kernel python" as shown in the following picture:但是,一段时间后它会抛出“无法为 kernel python 启动 session”的错误消息,如下图所示:

在此处输入图像描述

The top right corner of VS code is shown in the following picture: VS code右上角如下图所示:

在此处输入图像描述

Could anyone help me in fixing the issue?谁能帮我解决这个问题?

An issue was opened today in the Python VS Code repository that describes a similar problem.今天在 Python VS Code 存储库中打开了一个问题,描述了一个类似的问题。 Their recommended fix is to close VS Code and then revert the traitlets dependency to version 4.3.3 with this command:他们推荐的修复方法是关闭 VS Code,然后使用以下命令将traitlets依赖恢复到 4.3.3 版:

python -m pip install 'traitlets==4.3.3' --force-reinstall

I had the same issue starting yesterday with two new virtual environments and different python versions (3.8.1 and 3.8.5).从昨天开始,我在两个新的虚拟环境和不同的 Python 版本(3.8.1 和 3.8.5)中遇到了同样的问题。 I can confirm that Simm Enley's suggested terminal command worked for me.我可以确认 Simm Enley 建议的终端命令对我有用。

python -m pip install 'traitlets==4.3.3' --force-reinstall

It has to be executed from within the corresponding virtual environment.它必须在相应的虚拟环境中执行。 A newer version of traitlets (5.0.0) installed by VSCode into the new virtual environment in order to to run the Interactive Terminal caused the issue, it seems like.由 VSCode 安装到新的虚拟环境中以运行交互式终端的较新版本的 traitlets (5.0.0) 导致了这个问题,看起来是这样。

the reason is newer version of traitlets (5.0.0) installed by VSCode into the new virtual environment;原因是 VSCode 将更新版本的 traitlets (5.0.0) 安装到新的虚拟环境中; but the ipykernel and tornado is incompatible with ipykernel and tornado;但是 ipykernel 和 tornado 与 ipykernel 和 tornado 不兼容; run the code in Terminal: pip install --upgrade ipykernel pip install --upgrade tornado在终端中运行代码: pip install --upgrade ipykernel pip install --upgrade tornado

2023.01.15 - Problem description: Jupyter in VS Code got stuck at connecting to Python kernel 2023.01.15 - 问题描述:VS Code 中的 Jupyter 在连接到 Python 时卡住了 kernel 连接到内核

I was using VS Code version 1.74.3 (user setup) with the Release Python extension version v2022.20.2, having the version details shown below:我使用的是 VS Code 版本 1.74.3(用户设置)和版本Python 扩展版本 v2022.20.2,版本详细信息如下所示:

VS Code 关于细节 Python 扩展发布版本详细信息

My Python version was 3.10.6 64-bit:我的 Python 版本是 3.10.6 64 位:

Python 版本详细信息

I tried all of the above, and none worked for me to get Jupyter unstuck.我尝试了以上所有方法,但没有一个能让我摆脱 Jupyter 的困扰。

I ran the Python 3.10.6 setup to repair it, but that did not work:我运行了 Python 3.10.6 安装程序来修复它,但这没有用: 修复 Python 3.10.6

I updated various packages, but that did not work either:我更新了各种包,但这也不起作用:

  • pip install --upgrade ipykernel pip 安装 --upgrade ipykernel
  • pip install --upgrade traitlets pip 安装 --upgrade traitlets
  • pip install --upgrade tornado pip 安装——升级龙卷风

Some details from the above upgrades:上述升级的一些细节:

  • Requirement already satisfied: traitlets>=5.4.0要求已经满足:traitlets>=5.4.0
  • Requirement already satisfied: tornado>=6.1要求已经满足:tornado>=6.1
  • (from ipython>=7.23.1->ipykernel) (来自 ipython>=7.23.1->ipykernel)

★★★★★ After uninstalling and reinstalling VS Code, Jupyter worked as before. ★★★★★ 卸载并重新安装VS Code 后,Jupyter 工作正常。

When I installed the Pre-Release Python extension (by mistake),当我安装Pre-Release Python 扩展时(错误地), Python 扩展预发布版本详细信息

Jupyter got stuck again. Jupyter 又卡住了。 I uninstalled the Pre-Release Python extension, and re-installed the Release Python extension shown in the image above;我卸载了 Pre-Release Python 扩展,并重新安装了上图所示的Release Python 扩展; Jupyter worked again. Jupyter 再次工作。

I had the same problem and none of the solutions above worked for me.我遇到了同样的问题,上面的解决方案都不适合我。 I succeded to resolve the problem by dowgrading Jupyter version from v2022.11.1003412109 to v2022.9.1303220346 in the extension manager.我通过在扩展管理器中将 Jupyter 版本从 v2022.11.1003412109 降级到 v2022.9.1303220346 成功解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM