WSL2 上的 Jupyter 实验室 NetworkError 运行
Jupyter lab NetworkError running on WSL2
我在我的 WSL2 Ubuntu 上 运行 Jupyter 实验室,并在我的 Win10 PC 上的 Firefox 中访问它。它们 运行 在同一台机器上,因此不应该涉及“网络”。我是运行它是jupyter lab --no-browser
。服务器在终端中正常启动:
[I 11:17:40.843 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 11:17:40.885 LabApp] JupyterLab extension loaded from /home/muthur/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 11:17:40.886 LabApp] JupyterLab application directory is /home/muthur/anaconda3/share/jupyter/lab
[I 11:17:40.888 LabApp] Serving notebooks from local directory: /home/muthur
[I 11:17:40.888 LabApp] Jupyter Notebook 6.2.0 is running at:
[I 11:17:40.888 LabApp] http://localhost:8888/?token=...
[I 11:17:40.888 LabApp] or http://127.0.0.1:8888/?token=...
[I 11:17:40.888 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
但是当我在浏览器中启动它时,我首先收到“服务器连接错误:无法建立与 Jupyter 服务器的连接。JupyterLab 将继续尝试重新连接。请检查您的网络连接或 Jupyter 服务器配置。” ,在 F12 控制台中是由于 Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
重新加载选项卡或在新选项卡中打开它给了我 Firefox“连接失败”错误页面,说它无法建立与 127.0.0.1:8888
[= 的连接15=]
过去 2-3 个月我一直在使用此设置,没有出现任何问题。知道为什么现在会出现这种情况吗?如何解决?
They are running on the same machine, so there should be no "Network" involved.
信不信由你,Windows 和 WSL2 会话之间的通信肯定涉及网络。虽然 WSL1 运行“位于”主机 Windows 网络(伪桥接)中,但 WSL2 运行 在具有自己的虚拟 NIC 的单独 VM 中。默认情况下,NIC 在 Windows 接口之后。
这意味着需要端口转发,这样当您在 Windows 浏览器中访问 localhost
(127.0.0.1) 上的端口 8888
时,它会被转发到WSL2 实例的虚拟 NIC。
By default,这会自动发生(请参阅该页面上的 localhostForwarding
设置)。但是,有时它不会。通常,当 Windows 休眠或关闭并启用“快速重启”(也执行“迷你休眠”)时,它会“中断”。请注意,快速重启是 Windows 中的默认设置,因此很容易 运行 陷入此问题。
解决方案相当简单,假设这就是您遇到的问题:
- 退出任何 运行ning WSL 实例
wsl --shutdown
在 PowerShell 或 CMD 提示符下
- 重新启动您的 WSL 实例
在您下一次休眠之前,一切都会顺利进行。
如果在 上不起作用,请尝试更多信息和其他建议。
我在我的 WSL2 Ubuntu 上 运行 Jupyter 实验室,并在我的 Win10 PC 上的 Firefox 中访问它。它们 运行 在同一台机器上,因此不应该涉及“网络”。我是运行它是jupyter lab --no-browser
。服务器在终端中正常启动:
[I 11:17:40.843 LabApp] [jupyter_nbextensions_configurator] enabled 0.4.1
[I 11:17:40.885 LabApp] JupyterLab extension loaded from /home/muthur/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 11:17:40.886 LabApp] JupyterLab application directory is /home/muthur/anaconda3/share/jupyter/lab
[I 11:17:40.888 LabApp] Serving notebooks from local directory: /home/muthur
[I 11:17:40.888 LabApp] Jupyter Notebook 6.2.0 is running at:
[I 11:17:40.888 LabApp] http://localhost:8888/?token=...
[I 11:17:40.888 LabApp] or http://127.0.0.1:8888/?token=...
[I 11:17:40.888 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
但是当我在浏览器中启动它时,我首先收到“服务器连接错误:无法建立与 Jupyter 服务器的连接。JupyterLab 将继续尝试重新连接。请检查您的网络连接或 Jupyter 服务器配置。” ,在 F12 控制台中是由于 Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.
重新加载选项卡或在新选项卡中打开它给了我 Firefox“连接失败”错误页面,说它无法建立与 127.0.0.1:8888
[= 的连接15=]
过去 2-3 个月我一直在使用此设置,没有出现任何问题。知道为什么现在会出现这种情况吗?如何解决?
They are running on the same machine, so there should be no "Network" involved.
信不信由你,Windows 和 WSL2 会话之间的通信肯定涉及网络。虽然 WSL1 运行“位于”主机 Windows 网络(伪桥接)中,但 WSL2 运行 在具有自己的虚拟 NIC 的单独 VM 中。默认情况下,NIC 在 Windows 接口之后。
这意味着需要端口转发,这样当您在 Windows 浏览器中访问 localhost
(127.0.0.1) 上的端口 8888
时,它会被转发到WSL2 实例的虚拟 NIC。
By default,这会自动发生(请参阅该页面上的 localhostForwarding
设置)。但是,有时它不会。通常,当 Windows 休眠或关闭并启用“快速重启”(也执行“迷你休眠”)时,它会“中断”。请注意,快速重启是 Windows 中的默认设置,因此很容易 运行 陷入此问题。
解决方案相当简单,假设这就是您遇到的问题:
- 退出任何 运行ning WSL 实例
wsl --shutdown
在 PowerShell 或 CMD 提示符下- 重新启动您的 WSL 实例
在您下一次休眠之前,一切都会顺利进行。
如果在