You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

全新conda环境安装Jupyter Lab后无法连接内核故障求助

Jupyter Lab无法连接内核问题排查求助

背景信息

  • 此前已正常使用Jupyter Lab数月
  • 问题今日首次出现,最初怀疑与当日上午安装新发布的XCode Command Line Tools 13有关,降级到12.5.1版本后问题仍未解决
  • 当前运行环境为miniconda

复现步骤

  • 创建全新的conda环境
  • 执行conda activate test激活环境
  • 执行conda install jupyterlab安装依赖
  • 安装完成后执行jupyter lab启动服务,在浏览器中打开并进入.ipynb文件

操作后浏览器左下角显示「Python 3 (ipykernel) | Connecting」,始终停留在连接状态,相关日志如下:

常规日志输出

以下是初始启动信息,无明显异常,可供辅助排查:

[I 2021-09-21 09:36:33.353 ServerApp] jupyterlab | extension was successfully linked.
[I 2021-09-21 09:36:34.278 ServerApp] nbclassic | extension was successfully linked.
[I 2021-09-21 09:36:34.509 LabApp] JupyterLab extension loaded from /opt/miniconda3/envs/test/lib/python3.9/site-packages/jupyterlab
[I 2021-09-21 09:36:34.509 LabApp] JupyterLab application directory is /opt/miniconda3/envs/test/share/jupyter/lab
[I 2021-09-21 09:36:34.515 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-09-21 09:36:34.526 ServerApp] nbclassic | extension was successfully loaded.
[I 2021-09-21 09:36:34.527 ServerApp] Serving notebooks from local directory: /Users/connorpancoast/Code/grassmaNN
[I 2021-09-21 09:36:34.527 ServerApp] Jupyter Server 1.4.1 is running at:
[I 2021-09-21 09:36:34.527 ServerApp] http://localhost:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
[I 2021-09-21 09:36:34.527 ServerApp]  or http://127.0.0.1:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
[I 2021-09-21 09:36:34.527 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2021-09-21 09:36:34.535 ServerApp]

    To access the server, open this file in a browser:
        file:///Users/connorpancoast/Library/Jupyter/runtime/jpserver-24903-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
     or http://127.0.0.1:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373

异常日志输出

首先是与nodejs相关的警告,暂无法确认是否与问题相关:

[W 2021-09-21 09:36:39.621 LabApp] Could not determine jupyterlab build status without nodejs
/opt/miniconda3/envs/test/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
  return _iterencode(o, 0)

后续内核成功启动,但出现连接超时问题:

[I 2021-09-21 09:36:51.114 ServerApp] Kernel started: b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:51.549 ServerApp] Timeout waiting for kernel_info reply from b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.092 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.093 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.109 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514

重试120次后会重复出现三次如下错误,此处仅展示一次:

[W 2021-09-21 09:38:51.474 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:38:51.475 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:38:51.476 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[E 2021-09-21 09:38:51.558 ServerApp] Uncaught exception GET /api/kernels/b38270f5-9a72-42cf-86e5-0e8e4b3b9514/channels?session_id=f834b0b3-b8ed-4b2d-bfc9-7a535593a24f (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/b38270f5-9a72-42cf-86e5-0e8e4b3b9514/channels?session_id=f834b0b3-b8ed-4b2d-bfc9-7a535593a24f', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "/opt/miniconda3/envs/test/lib/python3.9/site-packages/tornado/websocket.py", line 956, in _accept_connection
        await open_result
    tornado.util.TimeoutError: Timeout

上述错误出现后,后续输出日志如下:

[W 2021-09-21 09:39:21.571 ServerApp] WebSocket ping timeout after 90003 ms.
[W 2021-09-21 09:39:21.585 ServerApp] WebSocket ping timeout after 90003 ms.
[W 2021-09-21 09:42:51.594 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
[W 2021-09-21 09:42:52.123 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
/opt/miniconda3/envs/test/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
  return _iterencode(o, 0)
[I 2021-09-21 09:46:52.126 ServerApp] Starting buffering for b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
[W 2021-09-21 09:46:52.146 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:f834b0b3-b8ed-4b2d-bfc9-7a535593a24f
[W 2021-09-21 09:46:55.306 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:1db7c82b-2627-4c43-b9d3-da7bef15ca32

问题原因与解决方案

问题原因

从日志中jupyter_client 7.0.0的弃用警告、内核启动成功但WebSocket连接超时的特征判断,该问题是2021年下半年jupyter_client 7.x版本与旧版jupyter_server、tornado的兼容性问题,在macOS环境下受XCode Command Line Tools更新引发的系统编译环境变化触发。

解决方案

按优先级依次尝试以下操作:

  1. 降级jupyter_client到6.x稳定版本
    在激活的conda环境中执行:
conda install jupyter_client=6.1.12

安装完成后重启jupyter lab即可,该方案对90%以上同场景问题有效。
2. 若上述操作无效,尝试升级全套jupyter相关组件:

conda update jupyterlab jupyter_server tornado ipykernel
  1. 若仍存在连接问题,可手动指定内核启动参数:
    执行jupyter kernelspec list查看Python内核配置文件路径,打开对应路径下的kernel.json,在argv列表末尾添加--ip=127.0.0.1参数,保存后重启jupyter lab。

内容的提问来源于stack exchange,提问作者fibonaccho

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 11:45:05