简体   繁体   中英

WSL2 and PySide6

I am trying to run a simple PySide6 app on WSL2

$ python3 -m venv venv
$ . ./venv/bin/activate
$ pip install PySide6
$ sudo apt install libopengl0 libegl1

My code:

import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QLabel
                                                     
if __name__ == "__main__":
    app = QApplication(sys.argv)
    label = QLabel("Hello World", alignment=Qt.AlignCenter)
    label.show()
    sys.exit(app.exec_())

When I run, I got the error

$ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0\n
$ python main.py
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

[1]    2557 abort      python main.py

Is it possible to run PySide applications using WSL2? If yes, how?

1, X Server https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242

i) install https://sourceforge.net/projects/vcxsrv/

ii) export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"

iii) run xev to test image

iv)include the command ii at the end of the /etc/bash.bashrc file:

2, sudo apt install pyside2-tools libopengl-dev

3, run python3 xxx.py it worked but still has some problem. output:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-dev'
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM