内核未在 Jupyter 实验室中连接

内核说正在连接,然后说没有内核 |断开连接。 我已经完全卸载了 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",NameError: name 'null' is not defined
[I 2021-08-01 21:01:58.362 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (2/5),NameError: name 'null' is not defined
sunsunfuqi 回答:内核未在 Jupyter 实验室中连接

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

本文链接:https://www.f2er.com/1429.html

大家都在问