在 VS Code 中调试 Jupyter Notebook 的问题:“需要 ipykernel 安装程序”和 Print 语句失败

Debugging Issue with Jupyter Notebooks in VS Code: 'ipykernel setup required' and Print Statement Failures

提问人:FluoroCarboChlor 提问时间:11/15/2023 最后编辑:FluoroCarboChlor 更新时间:11/15/2023 访问量:62

问:

尝试在 Visual Studio Code 中调试 Jupyter 笔记本时遇到问题。我有一个带有多个交互式小部件的单元格,使用 ipywidgets。当我开始调试时,我收到以下错误和警告:

[error] Failed to handle iopub message as a result of some comm message {
...
} Error: Cannot call start again
[warn] Cell completed with errors undefined

我可以很好地运行笔记本中的所有单元格,并且打印语句在几次执行中按预期工作,或者直到我尝试调试。在我尝试调试后,我收到一个对话框,上面写着“此功能需要 ipykernel 设置”,print 语句不再显示,并且类似命令也不产生任何输出。conda info

我尝试了以下步骤:

  • 更新、卸载和重新安装 ipykernel、Jupyter、Miniconda3 和 Python 扩展
  • 更新、卸载和重新安装 VS Code
  • 重新加载 VS Code 窗口
  • 完成 VS Code 和 Python 的卸载和重新安装,包括删除我的主目录中的相关文件夹、appdata 和程序文件。

这些步骤均未解决问题。很多时候,重新启动内核或重新加载窗口会暂时修复它,但现在调试无论如何都不起作用。 我认为问题与我的路径变量的配置方式有关,它们不允许 Miniconda3 与 VS Code 和 Jupyter 一起使用。

  • Miniconda3 安装路径:C:\Users\User\AppData\Local\miniconda3
  • VS Code 中的 Python 解释器路径:C:\Users\User\Desktop\Folder\.conda\python.exe
  • PATH 环境变量:
C:\Users\User\AppData\Local\miniconda3;
C:\Users\User\AppData\Local\miniconda3\Library\mingw-w64\bin;
C:\Users\User\AppData\Local\miniconda3\Library\usr\bin;
C:\Users\User\AppData\Local\miniconda3\Library\bin;
C:\Users\User\AppData\Local\miniconda3\Scripts;
C:\Users\User\AppData\Local\miniconda3\bin;
C:\Users\User\AppData\Local\miniconda3\condabin;
  • Conda 环境:
base                  *  C:\Users\User\AppData\Local\miniconda3
                         C:\Users\User\Desktop\Folder\.conda
                         c:\Users\User\Desktop\Folder\.conda

我使用的是以下版本:

Operating System: Windows 11 Enterprise Version 21H2
VS Code: 1.84.2
Python extension: v2023.20.0
Python: 3.10.12
IPython: 8.15.0
ipykernel: 6.25.0
ipywidgets: 8.1.1
jupyter_client: 8.6.0
jupyter_core: 5.5.0
jupyter_server: 2.10.0
jupyterlab: 4.0.8
nbclient: 0.8.0
nbconvert: 7.10.0
nbformat: 5.9.2
notebook: 7.0.6
qtconsole: not installed
traitlets: 5.7.1
Managed by Minconda3

这是conda list

# packages in environment at c:\Users\User\Desktop\Folder\.conda:
#
# Name                    Version                   Build  Channel
adjusttext                0.7.3.1                    py_1    conda-forge
asttokens                 2.0.5              pyhd3eb1b0_0
backcall                  0.2.0              pyhd3eb1b0_0
blas                      1.0                         mkl
boltons                   23.0.0          py310haa95532_0
boost-cpp                 1.82.0               h59b6b97_2
bottleneck                1.3.5           py310h9128911_0
brotli                    1.0.9                h2bbff1b_7
brotli-bin                1.0.9                h2bbff1b_7
brotli-python             1.0.9           py310hd77b12b_7
bzip2                     1.0.8                he774522_0
ca-certificates           2023.08.22           haa95532_0
cairo                     1.16.0               haedb8bc_5
cantera                   3.0.0           py310h3b7b6ab_2    conda-forge
certifi                   2023.7.22       py310haa95532_0
cffi                      1.15.1          py310h2bbff1b_3
charset-normalizer        2.0.4              pyhd3eb1b0_0
colorama                  0.4.6           py310haa95532_0
comm                      0.1.4              pyhd8ed1ab_0    conda-forge
comtypes                  1.1.14          py310haa95532_0
conda                     23.9.0          py310haa95532_0
conda-package-handling    2.2.0           py310haa95532_0
conda-package-streaming   0.9.0           py310haa95532_0
contourpy                 1.0.5           py310h59b6b97_0
cryptography              41.0.3          py310h89fc84f_0
cycler                    0.11.0             pyhd3eb1b0_0
debugpy                   1.6.7           py310hd77b12b_0
decorator                 5.1.1              pyhd3eb1b0_0
eigen                     3.3.7                h59b6b97_1
entrypoints               0.4             py310haa95532_0
et_xmlfile                1.1.0           py310haa95532_0
exceptiongroup            1.0.4           py310haa95532_0
executing                 0.8.3              pyhd3eb1b0_0
expat                     2.5.0                hd77b12b_0
fmt                       10.1.1               h181d51b_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hd3eb1b0_0
font-ttf-inconsolata      2.001                hcb22688_0
font-ttf-source-code-pro  2.030                hd3eb1b0_0
font-ttf-ubuntu           0.83                 h8b1ccd4_0
fontconfig                2.14.1               h9c4af85_2
fonts-anaconda            1                    h8fa9717_0
fonts-conda-ecosystem     1                    hd3eb1b0_0
fonttools                 4.25.0             pyhd3eb1b0_0
freetype                  2.12.1               ha860e81_0
fribidi                   1.0.10               h62dcd97_0
getopt-win32              0.1                  h2bbff1b_0
giflib                    5.2.1                h8cc25b3_3
glib                      2.69.1               h5dc1a3c_2
graphite2                 1.3.14               hd77b12b_1
graphviz                  2.50.0               h7eca76f_1
gst-plugins-base          1.18.5               h9e645db_0
gstreamer                 1.18.5               hd78058f_0
gts                       0.7.6                h63ab5a1_3
harfbuzz                  4.3.0                hb646838_1
hdf5                      1.14.2          nompi_h73e8ff5_100    conda-forge
icc_rt                    2022.1.0             h6049295_2
icu                       58.2                 ha925a31_3
idna                      3.4             py310haa95532_0
intel-openmp              2023.1.0         h59b6b97_46320
ipykernel                 6.25.0          py310h9909e9c_0
ipython                   8.15.0          py310haa95532_0
ipywidgets                8.1.1              pyhd8ed1ab_0    conda-forge
jedi                      0.18.1          py310haa95532_1
jpeg                      9e                   h2bbff1b_1
jsonpatch                 1.32               pyhd3eb1b0_0
jsonpointer               2.1                pyhd3eb1b0_0
jupyter_client            8.6.0           py310haa95532_0
jupyter_core              5.5.0           py310haa95532_0
jupyterlab_widgets        3.0.9              pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.4           py310hd77b12b_0
krb5                      1.21.2               heb0366b_0    conda-forge
lcms2                     2.12                 h83e58a3_0
lerc                      3.0                  hd77b12b_0
libaec                    1.1.2                h63175ca_1    conda-forge
libblas                   3.9.0              19_win64_mkl    conda-forge
libboost                  1.82.0               h3399ecb_2
libbrotlicommon           1.0.9                h2bbff1b_7
libbrotlidec              1.0.9                h2bbff1b_7
libbrotlienc              1.0.9                h2bbff1b_7
libcantera                3.0.0                h4d0b157_2    conda-forge
libcblas                  3.9.0              19_win64_mkl    conda-forge
libclang                  12.0.0          default_h627e005_2
libcurl                   8.4.0                hd5e4a3a_0    conda-forge
libdeflate                1.17                 h2bbff1b_1
libffi                    3.4.4                hd77b12b_0
libgd                     2.3.3                hd77b12b_3
libiconv                  1.16                 h2bbff1b_2
liblapack                 3.9.0              19_win64_mkl    conda-forge
libogg                    1.3.5                h2bbff1b_1
libopencv                 4.6.0                haa95532_5
libpng                    1.6.39               h8cc25b3_0
libprotobuf               3.20.3               h23ce68f_0
libsodium                 1.0.18               h62dcd97_0
libsqlite                 3.44.0               hcfcfb64_0    conda-forge
libssh2                   1.11.0               h7dfc565_0    conda-forge
libtiff                   4.5.1                hd77b12b_0
libvorbis                 1.3.7                he774522_0
libwebp                   1.2.4                hbc33d0d_1
libwebp-base              1.2.4                h2bbff1b_1
libxml2                   2.10.4               h0ad7f3c_1
libxslt                   1.1.37               h2bbff1b_1
libzlib                   1.2.13               hcfcfb64_5    conda-forge
lxml                      4.9.3           py310h09808a7_0
lz4-c                     1.9.4                h2bbff1b_0
matplotlib                3.8.0           py310haa95532_0
matplotlib-base           3.8.0           py310h4ed8f06_0
matplotlib-inline         0.1.6           py310haa95532_0
menuinst                  1.4.19          py310h59b6b97_0
mkl                       2023.2.0         h6a75c08_50496    conda-forge
mkl-service               2.4.0           py310h2bbff1b_1
mkl_fft                   1.3.8           py310h2bbff1b_0
mkl_random                1.2.4           py310h59b6b97_0
munkres                   1.1.4                      py_0
nest-asyncio              1.5.6           py310haa95532_0
numexpr                   2.8.7           py310h2cd9be0_0
numpy                     1.26.0          py310h055cbcc_0
numpy-base                1.26.0          py310h65a83cf_0
opencv                    4.6.0           py310ha7641e4_2
openjpeg                  2.4.0                h4fc8c34_0
openpyxl                  3.0.10          py310h2bbff1b_0
openssl                   3.1.4                hcfcfb64_0    conda-forge
packaging                 23.1            py310haa95532_0
pandas                    2.1.1           py310h4ed8f06_0
pango                     1.50.7               h78c2152_0
parso                     0.8.3              pyhd3eb1b0_0
pcre                      8.45                 hd77b12b_0
pdf2image                 1.16.3             pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5           pyhd3eb1b0_1003
pillow                    9.4.0           py310hd77b12b_0
pip                       23.3            py310haa95532_0
pixman                    0.40.0               h2bbff1b_1
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_1    conda-forge
platformdirs              3.10.0          py310haa95532_0
plotly                    5.17.0             pyhd8ed1ab_0    conda-forge
pluggy                    1.0.0           py310haa95532_1
ply                       3.11            py310haa95532_0
poppler                   22.12.0              h0bf3bde_3
poppler-data              0.4.11               haa95532_1
prompt-toolkit            3.0.36          py310haa95532_0
psutil                    5.9.0           py310h2bbff1b_0
pure_eval                 0.2.2              pyhd3eb1b0_0
py-opencv                 4.6.0                haa95532_5
pycosat                   0.6.6           py310h2bbff1b_0
pycparser                 2.21               pyhd3eb1b0_0
pygments                  2.15.1          py310haa95532_1
pyopenssl                 23.2.0          py310haa95532_0
pyparsing                 3.0.9           py310haa95532_0
pyqt                      5.15.10         py310hd77b12b_0
pyqt5-sip                 12.13.0         py310h2bbff1b_0
pysocks                   1.7.1           py310haa95532_0
pytesseract               0.3.13             pyhd8ed1ab_0    conda-forge
python                    3.10.12         h4de0772_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd3eb1b0_0
python-graphviz           0.20.1          py310haa95532_0
python-tzdata             2023.3             pyhd3eb1b0_0
python_abi                3.10                    4_cp310    conda-forge
pytz                      2023.3.post1    py310haa95532_0
pywin32                   305             py310h2bbff1b_0
pywinauto                 0.6.8           py310h5588dad_6    conda-forge
pyzmq                     25.1.1          py310hcd737a0_1    conda-forge
qt-main                   5.15.2               he8e5bd7_7
qt-webengine              5.15.9               h5bd16bc_7
qtwebkit                  5.212                h2bbfb41_5
requests                  2.31.0          py310haa95532_0
ruamel.yaml               0.17.21         py310h2bbff1b_0
ruamel.yaml.clib          0.2.6           py310h2bbff1b_1
ruamel_yaml               0.17.21         py310h2bbff1b_0
scipy                     1.11.3          py310h309d312_0
setuptools                68.0.0          py310haa95532_0
sip                       6.7.12          py310hd77b12b_0
six                       1.16.0             pyhd3eb1b0_1
sqlite                    3.41.2               h2bbff1b_0
stack_data                0.2.0              pyhd3eb1b0_0
sundials                  6.6.2                h2434545_1    conda-forge
tbb                       2021.8.0             h59b6b97_0
tenacity                  8.2.2           py310haa95532_0
tk                        8.6.12               h2bbff1b_0
toml                      0.10.2             pyhd3eb1b0_0
tomli                     2.0.1           py310haa95532_0
tornado                   6.3.3           py310h2bbff1b_0
tqdm                      4.65.0          py310h9909e9c_0
traitlets                 5.7.1           py310haa95532_0
truststore                0.8.0           py310haa95532_0
tzdata                    2023c                h04d1e81_0
ucrt                      10.0.20348.0         haa95532_0
urllib3                   1.26.18         py310haa95532_0
vc                        14.2                 h21ff451_1
vc14_runtime              14.36.32532         hdcecf7f_17    conda-forge
vs2015_runtime            14.36.32532         h05e6639_17    conda-forge
wcwidth                   0.2.5              pyhd3eb1b0_0
wheel                     0.41.2          py310haa95532_0
widgetsnbextension        4.0.9              pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0           py310haa95532_0
xz                        5.4.2                h8cc25b3_0
yaml-cpp                  0.8.0                hd77b12b_0
zeromq                    4.3.4                hd77b12b_0
zlib                      1.2.13               hcfcfb64_5    conda-forge
zstandard                 0.19.0          py310h2bbff1b_0
zstd                      1.5.5                hd43e919_0
python visual-studio-code jupyter-notebook ipywidgets miniconda

评论

0赞 MingJie-MSFT 11/16/2023
您能否提供最小的可重现示例,以帮助我们重现该问题。

答:

0赞 MingJie-MSFT 11/15/2023 #1

此功能需要 ipykernel 设置

这意味着 ipykernel 包未安装在当前的 jupyter 内核中。

您可以单击右上角的按钮来更改当前的 jupyter 内核。

enter image description here

另一种方法是在当前环境中安装 ipykernel 软件包。

评论

0赞 FluoroCarboChlor 11/15/2023
我安装了ipykernel。我已经卸载、重新安装和更新了几次。我将其列在 的输出中。在尝试调试之前,我也可以使用 ipykernel 的功能,但在调试后,ipykernel 停止工作。conda list