rakbar
rakbar

Reputation: 103

Windows Subsystem for Linux DISPLAY variable setup

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 shows nothing. How can I setup the DISPLAY variable?

Upvotes: 3

Views: 14297

Answers (1)

Michael S
Michael S

Reputation: 196

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.

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. Installing an X-server (Such as Xming).
  2. Telling the Windows Subsystem for Linux to use this X-server as the DISPLAY by setting the environment variable.

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.

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

export DISPLAY=:0

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

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

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.

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/


Edit: 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

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

Upvotes: 6

Related Questions