新建一个Jupyter notebook,发现内核显示error,报错的详情如下:
Traceback (most recent call last):
File "D:\software\anaconda\Lib\site-packages\tornado\web.py", line 1713, in _execute
result = await result
^^^^^^^^^^^^
File "D:\software\anaconda\Lib\asyncio\tasks.py", line 339, in __wakeup
future.result()
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 776, in run
yielded = self.gen.throw(*exc_info) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\notebook\services\sessions\handlers.py", line 74, in post
model = yield maybe_future(
^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 769, in run
value = future.result()
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 776, in run
yielded = self.gen.throw(*exc_info) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\notebook\services\sessions\sessionmanager.py", line 98, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 769, in run
value = future.result()
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 776, in run
yielded = self.gen.throw(*exc_info) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\notebook\services\sessions\sessionmanager.py", line 110, in start_kernel_for_session
kernel_id = yield maybe_future(
^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\tornado\gen.py", line 769, in run
value = future.result()
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\asyncio\futures.py", line 203, in result
raise self._exception.with_traceback(self._exception_tb)
File "D:\software\anaconda\Lib\asyncio\tasks.py", line 267, in _step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\notebook\services\kernels\kernelmanager.py", line 176, in start_kernel
kernel_id = await maybe_future(self.pinned_superclass.start_kernel(self, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_core\utils_init.py", line 158, in wrapped
return runner_map[name].run(inner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_core\utils_init.py", line 125, in run
return fut.result(None)
^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\concurrent\futures_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self._exception
File "D:\software\anaconda\Lib\asyncio\tasks.py", line 267, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_client\multikernelmanager.py", line 207, in async_start_kernel
starter = ensure_async(km.start_kernel(**kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_core\utils_init.py", line 158, in wrapped
return runner_map[name].run(inner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_core\utils_init.py", line 125, in run
return fut.result(None)
^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\concurrent\futures_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self._exception
File "D:\software\anaconda\Lib\asyncio\tasks.py", line 267, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_client\manager.py", line 93, in wrapper
raise e
File "D:\software\anaconda\Lib\site-packages\jupyter_client\manager.py", line 85, in wrapper
out = await method(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_client\manager.py", line 401, in _async_start_kernel
await self._async_launch_kernel(kernel_cmd, **kw)
File "D:\software\anaconda\Lib\site-packages\jupyter_client\manager.py", line 317, in _async_launch_kernel
connection_info = await self.provisioner.launch_kernel(kernel_cmd, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_client\provisioning\local_provisioner.py", line 205, in launch_kernel
self.process = launch_kernel(cmd, **scrubbed_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\site-packages\jupyter_client\launcher.py", line 167, in launch_kernel
raise ex
File "D:\software\anaconda\Lib\site-packages\jupyter_client\launcher.py", line 155, in launch_kernel
proc = Popen(cmd, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "D:\software\anaconda\Lib\subprocess.py", line 1026, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\software\anaconda\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
是不是头都麻了?
要解决这个问题,请按照以下步骤:
1. 访问C:\Users\ASUS\AppData\Roaming\jupyter\kernels\python3,找到kernel.json文件,将文件中的内容改为:
{
"argv": [
"C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python38\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python (base)",
"language": "python",
"metadata": {
"debugger": true
}
}
请注意,在 Windows 系统中,路径中的反斜杠 (\
) 在 JSON 文件中需要被转义,即使用两个反斜杠 (\\
)。在您的原始 kernel.json
文件中,路径被写作 "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\python.exe"
,而正确的写法应为 "C:\\Users\\ASUS\\AppData\\Local\\Programs\\Python\\Python38\\python.exe"
2. 更新IPython
pip install --upgrade jupyter ipython
3. 安装注册Python内核
python -m ipykernel install --user