2022年3月31日 星期四

[vscode, x11] How to set a X11 server for display the remote GUI app

How to set a X11 server for display the remote GUI app

井民全, Jing, mqjing@gmail.com

LT;DR

vscode

Install Remote development


Remote Machine:

export DISPLAY= [your-local-host-ip]:0.0


Local Host:

Install MobaXterm, launch it and wait. (the default X11 server was set as 0.0)




1. Setup the local host (Windows)

[Host] VSCode in Windows

Step 1: Enable the ssh remote forward

In vscode extension  [ssh remote], open the config

  ForwardX11 yes


E.g.


Step 2: Install a X server

I choose the MobaXterm.


Step 3: Start the MobaXterm, and wait


2. Setup the Guest (Linux)

[Guest] Setup the Display for gui app

Option 1: Setup the variable

export DISPLAY= [your-host-ip]:0.0

ex

export DISPLAY=192.168.24.1:0.0


Option 2: Write to the ~/.zshrc

Command


vi  ~/.zshrc


File: ~/.zshrc

....

export DISPLAY=192.168.24.1:0.0


source ~/.zshrc


3. Verification

On Guest, we worte a simple python app that will show a 3D chart on screen.

3.1. Python code

Step 1: the demo 3D code

File: test.py

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

plt.show()


Step 2: Run

python test.py


3.2. Result


  1. MobaXterm will prompt you a noti

             

  1. Show the result on host machine (Windows)


        


4. Reference

  1. https://github.com/microsoft/vscode-remote-release/issues/267