Put this into shell:startup folder (usually %AppData%\Microsoft\Windows\Start Menu\Programs\Startup\config.xlaunch
);
<?xml version="1.0" encoding="UTF-8"?>
<XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="-1" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="-screen 0 1920x1080@1" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>
- reference superuser.com/questions/1372854/do-i-launch-the-app-xlaunch-for-every-login-to-use-gui-in-ubuntu-wsl-in-windows
2. Set DISPLAY variable inside WSL to <wsl_hostname_ip>:0
route Display remote location to host machine
- ref https://stackoverflow.com/a/61110604/6875391
- will not work for Windows-based Pycharm, see 2.2a OR 2.2b
export DISPLAY=$(ip route | awk '/default via / {print $3; exit}' 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1
- Set local environment variable DISPLAY for vcXsrv Chrome GUI
- reference https://stackoverflow.com/a/57403093/6875391
import subprocess
import os
def _get_wsl_host_address() -> str:
"""
:return: ip:port for wsl host
"""
wsl_hostname_ip = subprocess.check_output("cat /etc/resolv.conf | grep nameserver | awk '{print $2}'", shell=True)
return f"{wsl_hostname_ip.decode('utf-8').strip()}:0"
if get_is_inside_wsl() in ["True", "true"]:
os.environ["DISPLAY"] = _get_wsl_host_address()
- reference https://kb.netgear.com/27476/How-do-I-set-a-static-IP-address-in-Windows
- check wsl hostname
wsl hostname -I
- in windows cmd - or (better)
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'
- set IP set, eg.
DISPLAY=172.18.80.1:0
in pycharm configuration environment settings