Jupyter Lab 中的内核未连接

Kernel not connecting in Jupyter Lab

内核说connecting然后说No Kernel |断开连接。 我已经干净地卸载了 anaconda 并使用卸载了所有 jupyter python -m pip uninstall -y jupyter jupyter_core jupyter-client jupyter-console jupyterlab_pygments notebook qtconsole nbconvert nbformat

在主目录中搜索 anaconda 或 jupyter 没有任何结果。

然后,我重新安装了anaconda,问题依旧。

起初,内核似乎正在连接一个新笔记本,但过了一段时间后,内核正在连接一个新笔记本。 (更新:我发现新笔记本一直连接到内核,直到打开旧笔记本。打开旧笔记本后,没有笔记本连接到内核)

我卡在这上面了。

以下是我在终端中得到的:

[I 2021-08-01 21:01:42.797 ServerApp] nbclassic | extension was successfully linked.
[I 2021-08-01 21:01:42.846 LabApp] JupyterLab extension loaded from /home/username/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 2021-08-01 21:01:42.846 LabApp] JupyterLab application directory is /home/username/anaconda3/share/jupyter/lab
[I 2021-08-01 21:01:42.849 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-08-01 21:01:42.852 ServerApp] nbclassic | extension was successfully loaded.
[I 2021-08-01 21:01:42.852 ServerApp] Serving notebooks from local directory: /home/username
[I 2021-08-01 21:01:42.853 ServerApp] Jupyter Server 1.4.1 is running at:
[I 2021-08-01 21:01:42.853 ServerApp] http://localhost:8888/lab?token=3d46a4259293e2afc5f584cf2d62586c5c553fd37e55e775
[I 2021-08-01 21:01:42.853 ServerApp]  or http://127.0.0.1:8888/lab?token=3d46a4259293e2afc5f584cf2d62586c5c553fd37e55e775
[I 2021-08-01 21:01:42.853 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2021-08-01 21:01:42.877 ServerApp] 
    
    To access the server, open this file in a browser:
        file:///home/username/.local/share/jupyter/runtime/jpserver-9804-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=3d46a4259293e2afc5f584cf2d62586c5c553fd37e55e775
     or http://127.0.0.1:8888/lab?token=3d46a4259293e2afc5f584cf2d62586c5c553fd37e55e775
[I 2021-08-01 21:01:48.429 LabApp] Build is up to date
[W 2021-08-01 21:01:49.469 ServerApp] Notebook Desktop/Link to foldername/ms-p/peroo/anl.ipynb is not trusted
[I 2021-08-01 21:01:52.346 ServerApp] Kernel started: 7bbe2308-8b30-4a4b-8b04-31aabe33d635
Traceback (most recent call last):
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/__init__.py", line 55, in <module>
    from .core.application import Application
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "/home/username/anaconda3/lib/python3.8/pdb.py", line 77, in <module>
    import code
  File "/home/username/Desktop/Projects/foldername/ms-p/peroo/code.py", line 535, in <module>
    "execution_count": null,
NameError: name 'null' is not defined
[I 2021-08-01 21:01:55.348 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (1/5), new random ports
Traceback (most recent call last):
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/__init__.py", line 55, in <module>
    from .core.application import Application
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "/home/username/anaconda3/lib/python3.8/pdb.py", line 77, in <module>
    import code
  File "/home/username/Desktop/Projects/foldername/ms-p/peroo/code.py", line 535, in <module>
    "execution_count": null,
NameError: name 'null' is not defined
[I 2021-08-01 21:01:58.362 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (2/5), new random ports
Traceback (most recent call last):
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/username/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/home/username/anaconda3/lib/python3.8/site-packages/ipykernel/connect.py", line 13, in <module>
    from IPython.core.profiledir import ProfileDir
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/__init__.py", line 55, in <module>
    from .core.application import Application
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/crashhandler.py", line 27, in <module>
    from IPython.core import ultratb
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/ultratb.py", line 112, in <module>
    from IPython.core import debugger
  File "/home/username/anaconda3/lib/python3.8/site-packages/IPython/core/debugger.py", line 47, in <module>
    from pdb import Pdb as OldPdb
  File "/home/username/anaconda3/lib/python3.8/pdb.py", line 77, in <module>
    import code
  File "/home/username/Desktop/Projects/foldername/ms-p/peroo/code.py", line 535, in <module>
    "execution_count": null,
NameError: name 'null' is not defined

您的 PYTHONPATH 中似乎有冲突。 pdb 尝试导入 code,但它没有获取其模块,而是看到了导致失败的 /home/username/Desktop/Projects/foldername/ms-p/peroo/code.py 文件。将此文件重命名为其他名称,例如mycode.py。这可能是一个常见问题,例如你不能有一个名为 statistics.py 的文件,因为你会隐藏内置的 statistics 模块。这在以下答案中得到了很好的解释:.