jupyter 笔记本内核不停地崩溃

jupyter notebook kernel crashing non-stop

我已经通过 Conda 安装了 Jupyter Notebook。已经使用了一个月没有任何问题。今天 Jupyter 内核突然开始崩溃并且无法重新启动。有一点需要注意。这可以毫无问题地打开:http://localhost:8888/tree 但是只要我打开任何笔记本(.ipynb 文件)就开始崩溃

(gpd) [arnuld@arch64 geo]$ jupyter-notebook

[I 13:01:24.389 NotebookApp] Serving notebooks from local directory:

/mnt/sda5/knuth/geo [I 13:01:24.389 NotebookApp] The Jupyter Notebook is running at:

[I 13:01:24.390 NotebookApp] http://localhost:8888/?token=d9ad51c90febcccc0b53d575c934396c4b28a65f307ef587

[I 13:01:24.390 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

[C 13:01:24.457 NotebookApp]

Copy/paste this URL into your browser when you connect for the first time, to login with a token:

    http://localhost:8888/?token=d9ad51c90febcccc0b53d575c934396c4b28a65f307ef587

[I 13:01:24.832 NotebookApp] Accepting one-time-token-authenticated connection from ::1

[I 13:01:51.437 NotebookApp] Kernel started: a04e2381-690f-410f-a07b-ede5f843b462

Traceback (most recent call last):

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec)

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals)

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/ipykernel_launcher.py", line 15, in from ipykernel import kernelapp as app

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/ipykernel/init.py", line 2, in from .connect import *

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/ipykernel/connect.py", line 13, in from IPython.core.profiledir import ProfileDir

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/IPython/init.py", line 55, in from .terminal.embed import embed

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/IPython/terminal/embed.py", line 17, in from IPython.terminal.ipapp import load_default_config

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/IPython/terminal/ipapp.py", line 28, in from IPython.core.magics import (

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/IPython/core/magics/init.py", line 18, in from .code import CodeMagics, MacroToEdit

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/IPython/core/magics/code.py", line 23, in from urllib.request import urlopen

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/urllib/request.py", line 86, in import email

File "/mnt/sda5/knuth/geo/email.py", line 1, in import pandas as pd

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/pandas/init.py", line 23, in from pandas.compat.numpy import *

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/site-packages/pandas/compat/init.py", line 63, in import http.client as httplib

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/http/client.py", line 71, in import email.parser

ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package

[I 13:07:48.306 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports

Traceback (most recent call last):

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec)

..... SNIPPED ......

File "/mnt/sda5/.miniconda3/envs/gpd/lib/python3.7/http/client.py", line 71, in import email.parser

ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package

[W 13:08:00.373 NotebookApp] KernelRestarter: restart failed

[W 13:08:00.374 NotebookApp] Kernel 182b657e-54af-420d-bcdb-910da9391f37 died, removing from map.

[W13:08:45.530 NotebookApp] Timeout waiting for kernel_info reply from 182b657e-54af-420d-bcdb-910da9391f37

[E 13:08:45.533 NotebookApp] Error opening stream: HTTP 404: Not Found (Kernel does not exist: 182b657e-54af-420d-bcdb-910da9391f37)

> 文件“/mnt/sda5/knuth/geo/email.py”,第 1 行,在

这一行说出了问题。

在我当前的工作目录中有一个名为 "email.py" 的文件,其中包含我的一些代码。由于 Jupyter Notebok 来自同一目录 运行,它认为它来自 email-parser 包,并开始寻找它只在标准包中寻找的东西。

两节课:

  • 在Python中,当前工作目录具有最高优先级,甚至高于标准安装位置。

  • 切勿在您所在的目录中保留文件的通用名称 运行 Jupyter Notebook 或 Python 否则它们将与标准包冲突。

感谢Min RK for solving this at gitter channel