gpt4 book ai didi

python - Jupyter 实验室和笔记本问题 : Kernel Error

转载 作者:行者123 更新时间:2023-12-05 08:51:50 31 4
gpt4 key购买 nike

看来我的一个内核不知何故被删除了。也许这就是我收到此错误的原因。我怎么可能修好它?我可以重新安装一些东西吗(也许是基础环境中的内核)?

如果没有更好的选择,作为最后的手段,我会尝试完全重新安装 anaconda:Default kernel in jupyter notebook (Python3) not working .

enter image description here

我试过使用以下方法:

  1. Installation of Jupyter Lab: requirements already satisfied
  2. Kernels don't show up when runnning "jupyter lab"
  3. UI says "No kernel" while I definitively have one
  4. Getting Kernel Error while running Jupyter Notebook in Python3
  5. https://ipython.readthedocs.io/en/latest/install/kernel_install.html
  6. https://medium.com/flatiron-engineering/recovering-from-a-jupyter-disaster-27401677aeeb

当前内核列表

jupyter kernelspec list

输出:

Available kernels:
python3 C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3
vpython C:\ProgramData\jupyter\kernels\vpython

但我必须有另一个与我的基本环境相关联的内核(我想它不知何故被删除了)。

C:\Users\raysu\Documents>conda env list
# conda environments:
#
base * C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64
astra_env C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\astra_env
bokeh_env C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\bokeh_env
sound_env C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\sound_env
tf_env C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\envs\tf_env
C:\Users\raysu\Anaconda3
C:\Users\raysu\Anaconda3\envs\pyforge
opencv_env C:\Users\raysu\AppData\Local\conda\conda\envs\opencv_env
test_env C:\Users\raysu\AppData\Local\conda\conda\envs\test_env

错误

Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\web.py", line 1699, in _execute
result = await result
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\notebook\services\sessions\handlers.py", line 72, in post
type=mtype))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 735, in run
value = future.result()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 88, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 735, in run
value = future.result()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 742, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 101, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 735, in run
value = future.result()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tornado\gen.py", line 209, in wrapper
yielded = next(result)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 168, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_client\manager.py", line 240, in start_kernel
self.write_connection_file()
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_client\connect.py", line 476, in write_connection_file
kernel_name=self.kernel_name
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_client\connect.py", line 141, in write_connection_file
with secure_write(fname) as f:
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_core\paths.py", line 404, in secure_write
win32_restrict_file_to_user(fname)
File "C:\Users\raysu\AppData\Roaming\Python\Python36\site-packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed: The specified procedure could not be found.

最佳答案

Solved the problem by editing the relevant kernelspec: kernel.json file after fresh installation of Anaconda.

详细解决方案

如前所述,我发现我有两个 kernelspecs。 (命令:jupyter kernelspec list)

  1. python3: C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3
  2. vpython: C:\ProgramData\jupyter\kernels\vpython

kernelspec 是一个 .json 文件,它维护 jupyter-notebook/lab 启动某个内核的内核规范。幸运的是,内核 vpython 正在运行,这帮助我缩小了位于 kernelpsec: python3。我必须更正 python 可执行文件 (python.exe) 的路径,这才解决了问题。

我想提一下,在这种情况下,以下两种资源派上了用场。在看到 kernelspec 文档的typical-structure 之后,我更加清楚了问题可能出在哪里。

注意:但是,由于我无法测试这个理论,所以我会请遇到类似问题的其他人先复制旧的 kernel.json 文件然后更新 python.exe 文件的路径。如果这解决了内核错误,则可能不需要完全重新安装 Anaconda。

Long story short:

如果您的 jupyter notebook/lab 环境显示内核错误,问题的根源很可能在 kernelspec 文件中:kernel.jsonpython.exe 的路径不正确。如果即使在重新安装 anaconda/jupyter-notebook/lab 后相同的 kernel error 仍然存在,这可能是一种更可能的情况。

例如,在我的例子中,python3-kernelspec 位于:

"C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3"

python.exe 位于:

"C:\Users\raysu\Anaconda3\python.exe"

但是,python-executable 的路径是错误的:它仍然显示旧安装的路径。在重新安装 anaconda 之后,这条路径发生了变化。因此,我必须通过编辑 kernel.json 文件来更新 python3 的 kernelspec。

# kernel.json file
{
"argv": [
"C:\\Users\\raysu\\Anaconda3\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}

如果这不能解决您的问题,请查阅以下两个文档。我因此浪费了4天。希望这个答案将来能对某人有所帮助。

什么派上用场了?

  1. https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html
  2. https://jupyter-client.readthedocs.io/en/stable/kernels.html

关于python - Jupyter 实验室和笔记本问题 : Kernel Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58459493/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com