适用于 Linux 的 Windows 子系统显示变量设置 [英] Windows Subsystem for Linux DISPLAY variable setup

查看:31
本文介绍了适用于 Linux 的 Windows 子系统显示变量设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用适用于 Linux 的 Windows 子系统,并尝试使用 Matplotlib 创建 python 绘图.但我收到以下错误

I'm experimenting with Windows Subsystem for Linux and am trying to create python plots using Matplotlib. But i get the following error

RuntimeError: Invalid DISPLAY variable

echo DISPLAY 什么也没显示.如何设置 DISPLAY 变量?

echo DISPLAY shows nothing. How can I setup the DISPLAY variable?

推荐答案

Linux 的 Windows 子系统不正式支持图形 GNU/Linux 桌面应用程序,因此我们无法保证调用我们选择的图形程序将作为 Windows 系统调用实现.

The Windows Subsystem for Linux doesn’t officially support graphical GNU/Linux desktop applications, so we have no guarantee that the calls made by our graphical program of choice will be implemented as windows system calls.

您遇到的主要问题是缺少这些程序的图形界面,称为X 服务器".我们可以尝试通过以下方式解决这个问题:

The main issue you are running into is the lack of a graphical interface to these programs, called an "X-server". We can try to get around this problem by:

  1. 安装 X 服务器(例如 Xming).
  2. 通过设置环境变量告诉适用于 Linux 的 Windows 子系统将此 X 服务器用作显示器.

对于(1),安装Xming只需下载并接受默认设置,它会自动启动并等待图形程序显示.

For (1), to install Xming, you can just download and accept the default settings, it will automatically launch and wait for graphical programs to display.

要解决 (2),在运行图形程序之前,请运行:

To address (2), before you run your graphical program, run:

export DISPLAY=:0

以便 bash 知道将您正在运行的程序的图形输出发送到哪里.

so that bash knows where to send the graphical output of the program you're running.

然后你可以尝试运行一个简单的图形程序(例如gvim或python的turtle模块).

Then you can try running a simple graphical program (for example gvim or python's turtle module).

同样,不能保证这适用于所有 GNU/Linux 应用程序,因为 Microsoft 并没有将每个 Linux 系统调用转换为 Windows 系统调用,并且如果您正在运行的图形程序进行了这样一个不受支持的调用,您的程序可能会崩溃.

Again, there is no guarantee that this will work for all GNU/Linux applications, since Microsoft has not translated every Linux system call to a Windows system call, and if the graphical program you're running makes such an unsupported call, your program may just crash.

这些说明的大部分取自以下指南,该指南展示了如何让 gvim 在适用于 Linux 的 Windows 子系统上工作:

Most of these instructions were taken from the following guide which shows how to get gvim working on Windows Subsystem for Linux:

http://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/

由于您还询问了检查 DISPLAY 中的内容,我补充说您可以通过运行来检查 DISPLAY 变量的值:

Since you also asked about checking what's in DISPLAY, I'm adding that you can check the value of the DISPLAY variable by running:

echo $DISPLAY

($ 确保 bash 将后面的内容解释为变量,而不是字符串文字.运行 echo DISPLAY 只会回显字符串 DISPLAY.)

(The $ ensures that bash interprets what follows as a variable, rather than a string literal. Running echo DISPLAY will just echo the string DISPLAY.)

这篇关于适用于 Linux 的 Windows 子系统显示变量设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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