问题描述
看来我的内核之一被删除了.也许这就是为什么我会收到此错误.我该如何解决?我可以重新安装某些东西(也许是在基本环境中的内核)吗?
It appears that somehow one of my kernels is deleted. And perhaps that's why I am getting this error. How could I possibly fix it? Can I reinstall something (the kernel in the base environment perhaps)?
如果没有更好的选择,我将尝试根据以下方式完全重新安装anaconda:.
If no better option is available, I would try reinstalling anaconda altogether as a last resort according to: Default kernel in jupyter notebook (Python3) not working.
我尝试使用以下内容:
- 安装Jupyter Lab:
requirements already satisfied
- 运行"jupyter实验室"时,内核不显示
- 当我明确拥有一个UI时,UI会说无内核"
- 在Python3中运行Jupyter Notebook时出现内核错误
- https://ipython.readthedocs.io/en/latest/install /kernel_install.html
- https://medium.com/flatiron-engineering /recovering-from-a-jupyter-disaster-27401677aeeb
- Installation of Jupyter Lab:
requirements already satisfied
- Kernels don't show up when runnning "jupyter lab"
- UI says "No kernel" while I definitively have one
- Getting Kernel Error while running Jupyter Notebook in Python3
- https://ipython.readthedocs.io/en/latest/install/kernel_install.html
- 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
但是我必须有另一个与我的基本环境相关联的内核(我想应该以某种方式删除了它).
But I must have another kernel (which I suppose somehow got deleted) associated with my base environment.
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.
推荐答案
详细解决方案
如前所述,我发现我有 2 kernelspecs
. (命令:jupyter kernelspec list
)
Solution in Detail
As reported earlier, I found that I had two kernelspecs
. (command: jupyter kernelspec list
)
- python3:
C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3
- vpython:
C:\ProgramData\jupyter\kernels\vpython
- python3:
C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3
- vpython:
C:\ProgramData\jupyter\kernels\vpython
kernelspec
是一个.json
文件,用于维护jupyter-notebook/lab启动特定内核的内核规范.幸运的是,内核 vpython
运行正常,这帮助我缩小了 kernelpsec: python3
内部问题的根源.我必须更正python可执行文件(python.exe
)的路径,从而解决了该问题.
The kernelspec
is a .json
file that maintains kernel-specifications for jupyter-notebook/lab to launch a certain kernel. Fortunately, the kernel vpython
was functioning and that helped me narrow down the source of the problem located inside kernelpsec: python3
. I had to correct the path to the python executable (python.exe
) and that solved the issue.
我想提一下,在这种情况下,以下两个资源非常有用.在看到kernelspec
文档的典型结构之后,我对问题可能出在哪里有了更清晰的认识.
I would like to mention that in this case the following two resources came handy. I got more clarity in where the problem could be, after I saw the typical-structure of the kernelspec
document.
注意:但是,由于我无法检验该理论,因此我会请遇到类似问题的其他人先复制旧的kernel.json
文件,然后将路径更新为python.exe
文件.如果这样可以解决 内核错误 ,则可能完全不需要重新安装Anaconda.
Note: However, since I cannot test this theory, I would ask anyone else in a similar problem, to first make a copy of the old kernel.json
file and then update the path to python.exe
file. If that resolves the kernel error, then reinstalling Anaconda altogether may not be necessary.
如果您的jupyter笔记本/实验室环境显示内核错误,则问题的根源很可能在kernelspec文件中: kernel.json
和 python.exe
不正确.如果即使重新安装了anaconda/jupyter-notebook/lab之后,同样的kernel error
仍然存在,则可能是更可能的情况.
If your jupyter notebook/lab environment shows you kernel error, most likely the source of the problem is inside the kernelspec file: kernel.json
and the path to python.exe
is incorrect. This could be a more likely scenario, if the same kernel error
persists even after fresh re-installation of anaconda/jupyter-notebook/lab.
例如,在我的情况下,python3-kernelspec
位于:
For instance, in my case, the python3-kernelspec
was located at:
"C:\Users\raysu\AppData\Roaming\jupyter\kernels\python3"
python.exe
位于:
"C:\Users\raysu\Anaconda3\python.exe"
但是, python-executable 的路径是错误的:它仍显示旧安装的路径.在安装anaconda之后,此路径已更改.因此,我不得不通过编辑kernel.json
文件来更新python3的kernelspec.
However, the path to the python-executable was wrong: it was still showing the path from the old installation. And post-anaconda-reinstallation, this path had changed. So, I had to update the kernelspec for python3 by editing kernel.json
file.
# kernel.json file
{
"argv": [
"C:\\Users\\raysu\\Anaconda3\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Python 3",
"language": "python"
}
如果这不能解决您的问题,请查阅以下两个文档.因此,我浪费了4天.希望这个答案将来能对某人有所帮助.
If this does not solve your problem, please consult the following two documents. I wasted 4 days because of this. Hopefully, this answer would help out someone in future.
- https://jupyter-notebook.readthedocs.io/en/stable /troubleshooting.html
- https://jupyter-client.readthedocs.io/en/stable /kernels.html
- https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html
- https://jupyter-client.readthedocs.io/en/stable/kernels.html
这篇关于Jupyter实验室和笔记本问题:内核错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!