X Server on WSL

From Autopilot Wiki
Jump to: navigation, search

To use PySide2 on Windows, specifically WSL, one needs to setup an X server.

A guide can be found here for Windows 10: https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242 which is largely reproduced below (thanks skeltoh for submitting this in #139)

VcXsrv Windows X Server

  • Download & install VcXsrv from https://sourceforge.net/projects/vcxsrv/
    • In the 'Extra Settings' screen, make sure you check "disable access control"
    • Save the configuration file before finishing
  • Allow VcXsrv in Windows Firewall
    • Windows Security -> Firewall & network protection -> Allow an app through firewall -> make sure VcXsrv has both public and private checked.
  • Use one of the following commands to set the 'DISPLAY environment variable in WSL:
export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"
export DISPLAY="`sed -n 's/nameserver //p' /etc/resolv.conf`:0"
export DISPLAY=$(ip route|awk '/^default/{print $3}'):0.0
    • add it to the /etc/bash.bashrc file with
      echo "<command>" >> /etc/bash.bashrc
  • Create an .xsession file
echo xfce4-session > ~/.xsession

And you should be good! Make sure that XLaunch is running