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

Jupyter Notebook报错:Bash(WSL) Kernel不存在问题求助

问题描述

此前已解决依赖不匹配问题,但更新WSL后,在安装了bash_kernel的Python环境启动的Jupyter Notebook中选择「New>Bash(WSL)」时,出现Kernel不存在错误。已安装GitBash,曾尝试降级tornado,但因Python 3.12.2版本无法执行,希望找到尽量无需添加环境变量的解决方案。

报错回溯

Traceback (most recent call last):
  File "C:\Users\<username>\AppData\Local\<vendor>\conda\envs\<env_name>\Lib\site-packages\tornado\web.py", line 1848, in _execute
    result = await result
             ^^^^^^^^^^^^
  File "C:\Users\<username>\AppData\Local\<vendor>\conda\envs\<env_name>\Lib\site-packages\jupyter_server\auth\decorator.py", line 73, in inner
    return await out
           ^^^^^^^^^
  File "C:\Users\<username>\AppData\Local\<vendor>\conda\envs\<env_name>\Lib\site-packages\jupyter_server\services\kernels\handlers.py", line 75, in get
    model = await ensure_async(km.kernel_model(kernel_id))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<username>\AppData\Local\<vendor>\conda\envs\<env_name>\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 513, in kernel_model
    self._check_kernel_id(kernel_id)
  File "C:\Users\<username>\AppData\Local\<vendor>\conda\envs\<env_name>\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 544, in _check_kernel_id
    raise web.HTTPError(404, "Kernel does not exist: %s" % kernel_id)
tornado.web.HTTPError: HTTP 404: Not Found (Kernel does not exist: <kernel-id>)

当前kernel.json内容

{
"argv": [
    "C:/Windows/System32/wsl.exe",
    "bash",
    "-c",
    "exec bash -l -i",
    "--",
    "{connection_file}"
],
"display_name": "Bash (WSL)",
"language": "bash"
}
解决方案

1. 修正kernel.json配置

当前的argv逻辑错误,bash无法处理Jupyter的connection_file参数,需调整为直接调用bash_kernel的启动入口,分两种情况处理:

  • 如果bash_kernel安装在当前启动Jupyter的Windows conda环境中
    修改kernel.json为以下内容,注意替换<username>和<env_name>为实际的用户名和conda环境名:
    {
        "argv": [
            "C:/Windows/System32/wsl.exe",
            "cmd.exe",
            "/c",
            "C:/Users/<username>/AppData/Local/<vendor>/conda/envs/<env_name>/python.exe",
            "-m",
            "bash_kernel",
            "-f",
            "{connection_file}"
        ],
        "display_name": "Bash (WSL)",
        "language": "bash"
    }
    
  • 如果bash_kernel安装在WSL内部的Python环境中
    先在WSL终端执行以下命令安装并注册bash_kernel:
    pip install bash_kernel
    python -m bash_kernel.install
    
    再修改Windows侧的kernel.json为:
    {
        "argv": [
            "C:/Windows/System32/wsl.exe",
            "python3",
            "-m",
            "bash_kernel",
            "-f",
            "{connection_file}"
        ],
        "display_name": "Bash (WSL)",
        "language": "bash"
    }
    

2. 验证WSL可用性

打开Windows命令提示符,执行wsl.exe bash -c "echo test",确认能正常输出test,确保WSL本身无运行问题。若GitBash干扰,可指定WSL内bash的绝对路径:wsl.exe /bin/bash -c "echo test"。

3. 解决tornado版本兼容问题

无需降级tornado,直接升级jupyter-server到兼容Python3.12的版本:

pip install --upgrade jupyter-server

内容的提问来源于stack exchange,提问作者ENIAC-6

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.01 21:54:53