内核说正在连接,然后说没有内核 |已断开连接。 我已经干净卸载了 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
我发现了同样的问题,并确定它只发生在 Chrome 标准浏览器上。隐身 Chrome 或 Firefox 不会出现同样的 ipykernel 无法连接的问题。
现在我使用以下命令在 Firefox 中打开 jupyter:
jupyter lab --browser Firefox
不确定浏览器有什么区别,但最近我遇到了无法从 Chrome 访问本地文件的问题,因此将研究这个问题,看看是否可以解决 Chrome 标准浏览器的问题。
只需将 *.py 文件和 *.IPYNB 文件放在单独的文件夹中即可。 完成。
看来您的
PYTHONPATH
存在冲突。 pdb
尝试导入 code
,但它没有获取其模块,而是看到您的 /home/username/Desktop/Projects/foldername/ms-p/peroo/code.py
文件,从而导致失败。将此文件重命名为其他名称,例如mycode.py
。这可能是一个常见问题,例如您不能拥有名为 statistics.py
的文件,因为您将隐藏内置 statistics
模块。这在以下问题的答案中得到了很好的解释:从脚本导入已安装的包会引发“AttributeError:模块没有属性”或“ImportError:无法导入名称”。
感谢您的回复,确实解决方案是将这些不同扩展名的文件放在不同的文件夹中。