在 WSL2 上运行的 Jupyter 实验室网络错误 [英] Jupyter lab NetworkError running on WSL2

查看:86
本文介绍了在 WSL2 上运行的 Jupyter 实验室网络错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 WSL2 Ubuntu 上运行 Jupyter 实验室,并在我的 Win10 PC 上的 Firefox 中访问它.它们在同一台机器上运行,所以不应该有网络".涉及.我将它作为 jupyter lab --no-browser 运行.服务器在终端中启动得很好:

I am running Jupyter lab on my WSL2 Ubuntu and accessing it in Firefox on my Win10 PC. They are running on the same machine, so there should be no "Network" involved. I am running it as jupyter lab --no-browser. The Server launches just fine in the terminal:

[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试图获取资源. 重新加载选项卡或以新的方式打开它一个给了我 Firefox 连接失败";错误页面,说无法与127.0.0.1:8888

But when I start it in my browser, I first get "Server Connection Error: A connection to the Jupyter server could not be established. JupyterLab will continue trying to reconnect. Check your network connection or Jupyter server configuration.", which in the F12 console is due to Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource. Reloading the tab or opening it in a new one gives me the Firefox "Connection failed" error page, saying that it cannot establish a connection to 127.0.0.1:8888

过去 2-3 个月我一直在使用此设置,没有出现任何问题.知道为什么现在会出现这种情况,以及如何解决吗?

I have been using this setup for the past 2-3 months without issue. Any idea why this crops up now, and how to solve it?

推荐答案

它们在同一台机器上运行,所以应该没有网络"涉及.

They are running on the same machine, so there should be no "Network" involved.

信不信由你,在 Windows 和 WSL2 会话之间进行通信时肯定会涉及到网络.虽然 WSL1 运行开启"主机 Windows 网络(伪桥接),WSL2 在一个单独的 VM 中运行,该 VM 具有自己的虚拟 NIC.默认情况下,该 NIC 在 Windows 界面之后 进行了 NAT.

Believe it or not, there's definitely a network involved when communicating between Windows and a WSL2 session. While WSL1 ran "on" the host Windows network (pseudo-bridged), WSL2 runs in a separate VM that has its own virtual NIC. That NIC is NAT'd behind the Windows interface by default.

这意味着需要进行端口转发,这样当你在 Windows 浏览器中访问 localhost (127.0.0.1) 上的端口 8888 时,它被转发到WSL2 实例的虚拟 NIC.

This means that port-forwarding is needed, so that when you access port 8888 on localhost (127.0.0.1) in the Windows browser, it is forwarded to the virtual NIC for the WSL2 instance.

默认,这会自动发生(请参阅该页面上的 localhostForwarding 设置).然而,有时它不会.通常,它中断"当 Windows 休眠或通过快速重启"关闭时启用(它也执行迷你休眠").请注意,快速重启是 Windows 中的默认设置,因此很容易遇到此问题.

By default, this happens automatically (see the localhostForwarding setting on that page). However, sometimes it doesn't. Typically, it "breaks" when Windows is hibernated or shut down with "Fast Restart" enabled (which also does a "mini-hibernate"). Note that Fast Restart is the default in Windows, so it's easy to run into this problem.

解决方案相当简单,假设这就是您所看到的问题:

The solution is fairly straightforward, assuming that this is the problem that you are seeing:

  • 退出任何正在运行的 WSL 实例
  • wsl --shutdown 在 PowerShell 或 CMD 提示符下
  • 重启你的 WSL 实例
  • Exit out of any running WSL instances
  • wsl --shutdown at the PowerShell or CMD prompt
  • Restart your WSL instance

在你下一次冬眠之前,一切都会好起来的.

Things will hopefully hum along just fine until your next hibernate.

如果在 此答案 中不起作用,请尝试更多信息和其他建议.

More info and other suggestions to try if that doesn't work at this answer.

这篇关于在 WSL2 上运行的 Jupyter 实验室网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆