jupyter kernel無法重啟/Error loading notebook/Failed to start the kernel/Unknown server error
前言
這個錯誤是在Ubuntu 16.04下出現的,使用pip list
可以得到以下jupyter及ipython版本的細節:
jupyter 1.0.0
jupyter-client 5.1.0
jupyter-console 5.1.0
jupyter-core 4.3.0
ipykernel: 4.6.1
ipython: 6.1.0
ipython-genutils: 0.2.0
ipywidgets: 6.0.0
錯誤訊息
An unknown error occurred while loading this notebook. This version can load notebook formats v4 or earlier. See the server log for details.
Traceback (most recent call last):
File “/usr/local/lib/python3.5/dist-packages/notebook/base/handlers.py”, line 516, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1055, in run
value = future.result()
File “/usr/local/lib/python3.5/dist-packages/tornado/concurrent.py”, line 238, in result
raise_exc_info(self._exc_info)
File “”, line 4, in raise_exc_info
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1063, in run
yielded = self.gen.throw(*exc_info)
File “/usr/local/lib/python3.5/dist-packages/notebook/services/sessions/handlers.py”, line 75, in post
type=mtype))
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1055, in run
value = future.result()
File “/usr/local/lib/python3.5/dist-packages/tornado/concurrent.py”, line 238, in result
raise_exc_info(self._exc_info)
File “”, line 4, in raise_exc_info
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1063, in run
yielded = self.gen.throw(*exc_info)
File “/usr/local/lib/python3.5/dist-packages/notebook/services/sessions/sessionmanager.py”, line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1055, in run
value = future.result()
File “/usr/local/lib/python3.5/dist-packages/tornado/concurrent.py”, line 238, in result
raise_exc_info(self._exc_info)
File “”, line 4, in raise_exc_info
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1063, in run
yielded = self.gen.throw(*exc_info)
File “/usr/local/lib/python3.5/dist-packages/notebook/services/sessions/sessionmanager.py”, line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 1055, in run
value = future.result()
File “/usr/local/lib/python3.5/dist-packages/tornado/concurrent.py”, line 238, in result
raise_exc_info(self._exc_info)
File “”, line 4, in raise_exc_info
File “/usr/local/lib/python3.5/dist-packages/tornado/gen.py”, line 307, in wrapper
yielded = next(result)
File “/usr/local/lib/python3.5/dist-packages/notebook/services/kernels/kernelmanager.py”, line 94, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File “/usr/local/lib/python3.5/dist-packages/jupyter_client/multikernelmanager.py”, line 110, in start_kernel
km.start_kernel(**kwargs)
File “/usr/local/lib/python3.5/dist-packages/jupyter_client/manager.py”, line 238, in start_kernel
self.write_connection_file()
File “/usr/local/lib/python3.5/dist-packages/jupyter_client/connect.py”, line 431, in write_connection_file
kernel_name=self.kernel_name
File “/usr/local/lib/python3.5/dist-packages/jupyter_client/connect.py”, line 136, in write_connection_file
with open(fname, ‘w’) as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘/root/.local/share/jupyter/runtime/kernel-d8c99eaa-9384-4339-8fc6-a86761e80a5d.json’
解決辦法
碰到這種問題完全沒有頭緒,只能上GitHub看看大佬們怎麼說。
找到不少相關問答說要在權限上動手腳,或是移除個別檔案,但這些方法對筆者的情況都起不了作用。
最後是看到Unable to create jupyter notebook這個討論串中blink1073的回答,他使用了最激進的方法,直接把整個資料夾刪除後重建。
rm -rf ~/.local/share/jupyter/
mkdir -p ~/.local/share/jupyter/runtime
chmod -R 777 ~/.local/share/jupyter
然後,問題就解決了。
但是看來看去,好像也沒人說出問題的真正原因。。。
其它辦法
最後還是附上筆者試過但失敗的方法,希望後進的同學不要再踩坑:
(以下這些問題給出的錯誤訊息不一定與筆者一樣,但同樣是無法開啟jupyter notebook的問題)
- 根據Unable to create jupyter notebook這個討論串中gunjannaik的回答,
修改~/.local/share/jupyter及其內容的權限:
chmod -R 777 ~/.local/share/jupyter
chown -R username:username ~/.local/share
- 根據IPython Notebook error: Error loading notebook中Mike Müller的回答及Jupyter Notebook Error: error loading notebook中提問者的做法,
把~/.ipython/profile_default/security/nbsignatures.db刪除(重命名):
mv ~/.ipython/profile_default/history.sqlite ~/.ipython/profile_default/history.sqlite.bak
mv ~/.ipython/profile_default/security/nbsignatures.db ~/.ipython/profile_default/security/nbsignatures.db.bak
mv ~/.local/share/jupyter/nbsignatures.db ~/.local/share/jupyter/nbsignatures.db.bak
注意事項:
在Cannot open or create new Jupyter notebooks中Q10Viking的回答中,他原本沒在jupyter notebook
後面加上--allow-root
,加了之後他的問題便成功解決。
參考連結
Unable to create jupyter notebook
Cannot open or create new Jupyter notebooks
IPython Notebook error: Error loading notebook
Jupyter Notebook Error: error loading notebook