WSL 2:从 Windows 10 Bash Shell 运行图形 Linux 桌面应用程序“错误 E233:无法打开显示" [英] WSL 2: Run Graphical Linux Desktop Applications from Windows 10 Bash Shell "Error E233: cannot open display"
问题描述
如何从 Windows 10 的 Bash Shell 运行图形 Linux 桌面应用程序?
How to run graphical Linux desktop applications from Windows 10’s Bash Shell?
首先,我按照 此处如下:
(1) 已安装 Windows 10 Pro Insider Preview Build 19619.
(1) Installed Windows 10 Pro Insider Preview Build 19619.
(2) 安装了 Ubuntu Linux 发行版.
(2) Installed Ubuntu Linux distribution.
(3) 将发行版本从 WSL 1 更改为 WSL 2.
(3) Changed the distribution version from WSL 1 to WSL 2.
其次,为了从 Windows 10 的 Bash Shell 启用图形 Linux 桌面应用程序,我按照以下步骤操作 这里如下:
Second, to enable graphical Linux desktop applications from Windows 10’s Bash Shell, I followed the following steps as shown here as follows:
(4) 我安装了一个 X 服务器,它是 Xming
(4) I installed an X Server that is Xming
(5) 安装基于 GTK 的图形 vim 编辑器作为测试使用:
(5) Installed graphical GTK-based vim editor as test using:
sudo apt-get install vim-gtk
(6) 设置我的显示环境变量
(6) Set my display environment variable
导出显示=:0
(7) 启动应用程序
gvim
然而,这并没有解决应用程序的问题,我收到了以下错误:
However, this did not lunch the application and I got the following error:
E233: cannot open display
Press ENTER or type command to continue
E852: The child process failed to start the GUI
Press ENTER or type command to continue
知道为什么会出现这个错误吗?
Any idea why this error is occurring?
推荐答案
WSL2 中的网络子系统与 WSL1 中使用的不同.您必须考虑差异才能访问在 Windows 和 Linux 上运行的网络应用:
The networking subsystem in WSL2 is different than the used in WSL1. You must consider the differences to access networking apps running on Windows and on Linux:
- 在 WSL1 中,Linux 使用与 Windows 主机相同的 IP 地址,然后,您可以使用
localhost
或127.0.0.1
访问应用程序 - 在 WSL2 中,Linux 在轻量级虚拟机上运行,并具有不同的 IP 地址.要访问在 Windows 主机上运行的网络应用,您必须使用 Windows IP 地址.
有多种方法可以确定 Windows 主机中的 IP 地址.您可以在 WSL Linux 中运行以下命令:
There are many ways to determine the IP addresses in the Windows host. You may run the following commands in your WSL Linux:
cat/etc/resolv.conf
显示Windows中eth0
接口的IP地址ipconfig.exe
显示 Windows 主机中的所有 IP 配置route.exe print
显示 Windows 主机中的网络路由配置
cat /etc/resolv.conf
shows the IP address of theeth0
interface in Windowsipconfig.exe
shows the all the IP configuration in the Windows hostroute.exe print
shows the network routing configuration in the Windows host
根据 Microsoft 文档,您可以设置 DISPLAY 变量,检查 /etc/resolv.conf
文件中的 nameserver
.(@fqquiner 和 @VPraharsha 已经提到了这一点)
Based on the Microsoft documentation, you may set the DISPLAY variable checking the nameserver
in the /etc/resolv.conf
file. (@fqquiner and @VPraharsha already mentioned this)
export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0
但是,我在使用此解决方案时遇到了问题,可能是因为我使用带有 WiFi 连接和多个虚拟网络的笔记本电脑.我没有使用之前的解决方案,而是使用 route.exe
并检查默认网关中使用的接口来确定 Windows IP 地址.
However, I had problems using this solution, probably because I use my notebook with a WiFi connection and multiple virtual networks. Instead of the previous solution, I determine the Windows IP address using route.exe
and checking the interface used in the default gateway.
export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0
在.profile
中设置DISPLAY变量您可以在 ~/.profile
文件中设置 DISPLAY 变量.我使用了以下代码:
Setting the DISPLAY variable in the .profile
You may set the DISPLAY variable in your ~/.profile
file. I used the following code:
# set DISPLAY to use X terminal in WSL
# in WSL2 the localhost and network interfaces are not the same than windows
if grep -q WSL2 /proc/version; then
# execute route.exe in the windows to determine its IP address
DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0
else
# In WSL1 the DISPLAY can be the localhost address
if grep -q icrosoft /proc/version; then
DISPLAY=127.0.0.1:0.0
fi
fi
这篇关于WSL 2:从 Windows 10 Bash Shell 运行图形 Linux 桌面应用程序“错误 E233:无法打开显示"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!