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

Jupyter Notebook启动内核失败:[WinError 2] 系统找不到指定文件

Jupyter Notebook启动内核失败:[WinError 2] 系统找不到指定文件

问题描述

我在PC上安装了Python 3.12.5后,通过pip install notebook安装了Jupyter Notebook。运行jupyter notebook能正常打开界面,但尝试创建新的Notebook使用时,弹出了内核启动失败的错误:
界面错误描述:界面显示“Kernel error”提示,说明无法启动Python内核,下方有查看日志详情的选项。

同时命令提示符中输出的错误日志如下:

[E 2024-12-11 02:52:25.760 ServerApp] [WinError 2] The system cannot find the file specified
    Traceback (most recent call last):
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 87, in wrapper
        out = await method(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 439, in _async_start_kernel
        await self._async_launch_kernel(kernel_cmd, **kw)
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 354, in _async_launch_kernel
        connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\provisioning\local_provisioner.py", line 210, in launch_kernel
        self.process = launch_kernel(cmd, **scrubbed_kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 170, in launch_kernel
        raise ex
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 155, in launch_kernel
        proc = Popen(cmd, **kwargs)  # noqa
               ^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1538, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    FileNotFoundError: [WinError 2] The system cannot find the file specified
[E 2024-12-11 02:52:25.766 ServerApp] [WinError 2] The system cannot find the file specified
    Traceback (most recent call last):
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\multikernelmanager.py", line 232, in _add_kernel_when_ready
        await kernel_awaitable
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_core\utils\__init__.py", line 198, in ensure_async
        result = await obj
                 ^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 784, in wrapped_method
        raise err
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 748, in wrapped_method
        out = await method(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 853, in start_kernel
        return await super().start_kernel(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 96, in wrapper
        raise e
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 87, in wrapper
        out = await method(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 439, in _async_start_kernel
        await self._async_launch_kernel(kernel_cmd, **kw)
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 354, in _async_launch_kernel
        connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\provisioning\local_provisioner.py", line 210, in launch_kernel
        self.process = launch_kernel(cmd, **scrubbed_kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 170, in launch_kernel
        raise ex
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 155, in launch_kernel
        proc = Popen(cmd, **kwargs)  # noqa
               ^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1538, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    FileNotFoundError: [WinError 2] The system cannot find the file specified
[W 2024-12-11 02:52:25.772 ServerApp] 500 POST /api/sessions?1733860345564 (::1): [WinError 2] The system cannot find the file specified
[W 2024-12-11 02:52:25.773 ServerApp] wrote error: '[WinError 2] The system cannot find the file specified'
    Traceback (most recent call last):
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\sessions\handlers.py", line 90, in post
        s_model = await sm.create_session(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\sessions\sessionmanager.py", line 285, in create_session
        kernel_id = await self.start_kernel_for_session(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\sessions\sessionmanager.py", line 343, in start_kernel_for_session
        kernel_id = await self.kernel_manager.start_kernel(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 233, in _async_start_kernel
        kernel_id = await self.pinned_superclass._async_start_kernel(self, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\multikernelmanager.py", line 283, in _async_start_kernel
        raise km.ready.exception()  # type: ignore[misc]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\multikernelmanager.py", line 232, in _add_kernel_when_ready
        await kernel_awaitable
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_core\utils\__init__.py", line 198, in ensure_async
        result = await obj
                 ^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 784, in wrapped_method
        raise err
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 748, in wrapped_method
        out = await method(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_server\services\kernels\kernelmanager.py", line 853, in start_kernel
        return await super().start_kernel(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 96, in wrapper
        raise e
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 87, in wrapper
        out = await method(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 439, in _async_start_kernel
        await self._async_launch_kernel(kernel_cmd, **kw)
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\manager.py", line 354, in _async_launch_kernel
        connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\provisioning\local_provisioner.py", line 210, in launch_kernel
        self.process = launch_kernel(cmd, **scrubbed_kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 170, in launch_kernel
        raise ex
      File "C:\Program Files\Python312\Lib\site-packages\jupyter_client\launcher.py", line 155, in launch_kernel
        proc = Popen(cmd, **kwargs)  # noqa
               ^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1026, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "C:\Program Files\Python312\Lib\subprocess.py", line 1538, in _execute_child
        hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      FileNotFoundError: [WinError 2] The system cannot find the file specified

解决方案

嘿,这个问题我之前帮同事解决过,本质就是Jupyter找不到Python内核的执行路径,给你几个靠谱的解决步骤:

  • 重新注册Python内核
    最常见的原因是Jupyter的内核配置指向了错误的路径,执行下面的命令重新注册内核:

    # 先升级ipykernel组件
    pip install --upgrade ipykernel
    # 将当前Python版本注册为Jupyter可用的内核
    python -m ipykernel install --user --name=python312 --display-name="Python 3.12"
    

    完成后重启Jupyter,选择刚注册的Python 3.12内核试试。

  • 检查Python环境变量
    有时候Python的安装目录没加到系统环境变量里,导致Jupyter找不到:

    1. 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
    2. 在系统变量的Path中添加C:\Program Files\Python312\和C:\Program Files\Python312\Scripts\
    3. 重启命令提示符和Jupyter再尝试
  • 使用虚拟环境隔离依赖
    Python 3.12和Jupyter的部分组件可能存在兼容性冲突,用虚拟环境可以彻底解决:

    # 创建一个专门给Jupyter用的虚拟环境
    python -m venv jupyter_env
    # 激活虚拟环境(Windows命令提示符下执行)
    jupyter_env\Scripts\activate
    # 在虚拟环境中安装Jupyter和内核
    pip install notebook ipykernel
    # 启动Jupyter
    jupyter notebook
    

    这个干净的环境几乎能解决所有路径相关的问题。

备注:内容来源于stack exchange,提问作者lokalhangatt

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 17:39:35