我正在尝试使用 miniconda 运行 jupyter lab,但 Jupyter 在与内核连接时遇到问题。下面是一些背景信息、我已完成的步骤以及生成的代码。
conda activate test
conda install jupyterlab
jupyter lab
打开浏览器并导航到我的 .ipynb
现在,浏览器左下角写着“Python 3 (ipykernel) | Connecting”,这没什么好说的。以下是日志摘要:
这是最初的信息(我认为其中不包含任何新颖的内容,但可能有助于回答您可能有的一些我没有想到的问题):
[I 2021-09-21 09:36:33.353 ServerApp] jupyterlab | extension was successfully linked.
[I 2021-09-21 09:36:34.278 ServerApp] nbclassic | extension was successfully linked.
[I 2021-09-21 09:36:34.509 LabApp] JupyterLab extension loaded from /opt/miniconda3/envs/test/lib/python3.9/site-packages/jupyterlab
[I 2021-09-21 09:36:34.509 LabApp] JupyterLab application directory is /opt/miniconda3/envs/test/share/jupyter/lab
[I 2021-09-21 09:36:34.515 ServerApp] jupyterlab | extension was successfully loaded.
[I 2021-09-21 09:36:34.526 ServerApp] nbclassic | extension was successfully loaded.
[I 2021-09-21 09:36:34.527 ServerApp] Serving notebooks from local directory: /Users/connorpancoast/Code/grassmaNN
[I 2021-09-21 09:36:34.527 ServerApp] Jupyter Server 1.4.1 is running at:
[I 2021-09-21 09:36:34.527 ServerApp] http://localhost:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
[I 2021-09-21 09:36:34.527 ServerApp] or http://127.0.0.1:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
[I 2021-09-21 09:36:34.527 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2021-09-21 09:36:34.535 ServerApp]
To access the server, open this file in a browser:
file:///Users/connorpancoast/Library/Jupyter/runtime/jpserver-24903-open.html
Or copy and paste one of these URLs:
http://localhost:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
or http://127.0.0.1:8888/lab?token=fa21e773398a0c8bbeccdb7a67ffb20950bac831209b9373
此后事情就变得奇怪了。
首先是关于
nodejs
的警告,这可能重要也可能不重要。
[W 2021-09-21 09:36:39.621 LabApp] Could not determine jupyterlab build status without nodejs
/opt/miniconda3/envs/test/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
return _iterencode(o, 0)
接下来,内核启动,但出现连接超时。
[I 2021-09-21 09:36:51.114 ServerApp] Kernel started: b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:51.549 ServerApp] Timeout waiting for kernel_info reply from b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.092 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.093 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:37:56.109 ServerApp] Nudge: attempt 10 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
我不确定为什么会发生三个单独的“微移过程”,但在 120 次微移尝试(如图所示)之后,此错误消息也出现了 3 次,由于空间原因未显示:
[W 2021-09-21 09:38:51.474 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:38:51.475 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[W 2021-09-21 09:38:51.476 ServerApp] Nudge: attempt 120 on kernel b38270f5-9a72-42cf-86e5-0e8e4b3b9514
[E 2021-09-21 09:38:51.558 ServerApp] Uncaught exception GET /api/kernels/b38270f5-9a72-42cf-86e5-0e8e4b3b9514/channels?session_id=f834b0b3-b8ed-4b2d-bfc9-7a535593a24f (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/api/kernels/b38270f5-9a72-42cf-86e5-0e8e4b3b9514/channels?session_id=f834b0b3-b8ed-4b2d-bfc9-7a535593a24f', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/opt/miniconda3/envs/test/lib/python3.9/site-packages/tornado/websocket.py", line 956, in _accept_connection
await open_result
tornado.util.TimeoutError: Timeout
之后,出现:
[W 2021-09-21 09:39:21.571 ServerApp] WebSocket ping timeout after 90003 ms.
[W 2021-09-21 09:39:21.585 ServerApp] WebSocket ping timeout after 90003 ms.
[W 2021-09-21 09:42:51.594 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
[W 2021-09-21 09:42:52.123 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
/opt/miniconda3/envs/test/lib/python3.9/json/encoder.py:257: UserWarning: date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.
return _iterencode(o, 0)
[I 2021-09-21 09:46:52.126 ServerApp] Starting buffering for b38270f5-9a72-42cf-86e5-0e8e4b3b9514:ee46fa70-0af0-489d-8993-acf4f55bf3aa
[W 2021-09-21 09:46:52.146 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:f834b0b3-b8ed-4b2d-bfc9-7a535593a24f
[W 2021-09-21 09:46:55.306 ServerApp] Replacing stale connection: b38270f5-9a72-42cf-86e5-0e8e4b3b9514:1db7c82b-2627-4c43-b9d3-da7bef15ca32
我还使用 Jupyter Lab 和 Miniconda,这是我几天前所做的。
看来你需要安装node.js和ipykernel:
conda install nodej ipykernel
此外,我在某处读到您需要“告诉”Jupyter Lab 使用您的环境,如下所示:
python -m ipykernel install --user --name test --display-name “enviroment_test”
请注意,test是您的环境名称,“enviroment_test”是将在 Jupyter 中显示的名称。
最后,我建议从 conda-forge 安装 Jupyter:
conda install jupyterlab -c conda-forge
观察:所有这些都需要在激活您想要的环境的情况下完成
我也遇到了同样的错误,有解决办法吗?