The goal of this tip is to provide a detailed description of how to utilize graphical applications from the remote server and view them at local machine without delay (e.g. visualize matplotlib plots/videos created at server).
A simple and effective way is to use ipympl. Add the following line in the jupyter notebook after importing matplotlib
%matplotlib widget
Refer to this link https://github.com/matplotlib/ipympl for more info about ipympl. Ipympl works great with static plots but not for videos which require real-time rendering.
General pipeline:
- Install X11 forwarding related softwares on server.
- Install X11 forwarding related softwares on local computer.
- Configure sshd_config and ssh_config on server.
- Configure sshd_config and ssh_config on local computer.
- Set display address using local computer address.
Server: WSL2 (Windows Subsystem for Linux 2) Local: MacOS
useful link: https://www.youtube.com/watch?v=4SZXbl9KVsw
- Install VcSsrv Windows X Server and follow the default settings.
- Allow administrator access if popped up.
- Launch the XLaunch app on desktop and allow "Disable access control" in "Extra settings". Follow defualts for others.
- Allow "Public networks" for firewall.
useful link: https://www.cyberciti.biz/faq/apple-osx-mountain-lion-mavericks-install-xquartz-server/
- Install XQuanrtz on mac
- Reboot the computer.
- Make sure that "X11Forwarding yes" and other X11 related settings are allowed in sshd_config
sudo nano /etc/ssh/sshd_config
uncomment or add the setting if necessary. Usually just check all X11 related settings are allowed. 2. Again, make sure all X11 related settings are allowed at local machine,
sudo nano /etc/ssh/ssh_config
and check all related settings. This should be done on WSL2 terminal.
Repeat step 3 at mac terminal.
- Get display addresses of server and local machine
- Server (IP address)
hostname -I
or
ip addr show
- Local machine (this might not be your IP address, usually is 127.0.0.1)!!!
nano /etc/hosts
- Configure the display address (the address you want the applications/plots to display)
- If it is on server (WSL2):
export DISPLAY={YOUR_DISPLAY_ADDRESS}:0.0
this is because Windows uses IP_address:0.0 as the defualt.
- If it is at local machine (MacOS):
export DISPLAY={YOUR_DISPLAY_ADDRESS}:10.0
this is because MacOS uses IP_address:10.0
- Set LIBGL_ALWAYS_INDIRECT variable
export LIBGL_ALWAYS_INDIRECT=1
- SSH your server
- Configure the display address
- Check a simple application
xeyes
You should see an eye popped up at your local machine.
- Error: Can't open display: X.X.X.X:10:0
Solution: Your display address is not configured correctly. 1) Check whether X11 are given access in the files. 2) Check DISPLAY variable using
echo $DISPLAY
- Restart XLauncher at WSL. 4) Reconnect to your server.