WSL2 uses xrdp to implement Liunx graphical desktop

 Because when using wsl to run code, pyplot is needed to visualize the data, but I found that

import matplotlib.pyplot as plt
# other code
plt.show()

No image was drawn after  plt.show() that, because   the default backend of  matplotlibplt.show() on wsl is Agg, which is a dumb backend, that  is, nothing will happen after that, so I used xrdp+xfce4 to achieve remote graphical desktop access. method, the results show that the effect of the picture is not bad.

Let me share the installation process below:

1. Installation package

Update first, then install. There are only two packages xfce4in total.xrdp

$ sudo apt update
$ sudo apt install -y xfce4 xrdp

During the installation of xfce4, you will be prompted to choose to display the management DM selection. It is recommended to use   lightdm 

 If you miss the wizard that appears during the installation process, you can execute the following command to reset DM after the installation is complete.

$ sudo dpkg-reconfigure lightdm

 

 2. Modify xrdp default port

 Since  xrdpthe default configuration after installation uses the same port as the Windows Remote Desktop 3389 , in order to prevent conflicts with the Windows Remote Desktop, it is recommended to change it to another port.

$ sudo vim /etc/xrdp/xrdp.ini
# 修改下面这一行,将默认的3389改成其他端口即可
port=3390

3. Specify the login session type for the current user

It is important to note this step. If not set, it will cause the remote desktop connection to crash later.

$ vim ~/.xsession

# 写入下面内容(就一行)
xfce4-session

4. Start xrdp

Since it cannot be used in WSL2 systemd, it needs to be started manually.

$ sudo /etc/init.d/xrdp start

5. Remote access

Run the command to open the remote desktop connection in Windows system   mstsc and enter the address localhost:3390

 

 Note that the port number here should be consistent with the modified configuration above.

 Enter the account and password used in the WSL2 subsystem to log in!

 It looks pretty good, but it’s actually quite silky smooth to use.

Sixth, the following shows my interface

I executed my code in the terminal, and the picture appeared as expected.

 

Reference: WSL2 uses xrdp to implement graphical desktop - Zhihu (zhihu.com)

Guess you like

Origin blog.csdn.net/weixin_45897172/article/details/128447323