WSL2下的PyQt5报错XCB找不到

前言

最近在WSL2上搬点砖,结果报xcb错误。

$ python test.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, webgl, xcb.

Aborted

搜索了一篇文章:在Ubuntu(WSL2)上使用PyQt5时,GUI周围出现错误,写得比较清楚了。

略微有几个细节,记一下,免得下次找。

过程

整个过程与原Po的文章基本一样。

  1. export QT_DEBUG_PLUGINS=1
  2. ldd /path-to-lib/libqxcb.so | grep "not found"
  3. sudo apt install libxxxx0 libxxxx1

QT插件

QT的很多功能使用插件来实现的,也就是利用动态链接库实现特定功能的一种方式。

在插件开发时,声明一个接口,并把接口注册到QObject体系中。

ldd

ldd的帮助页上写:ldd - print shared object dependencies。

也就是列出动态链接库的依赖项。

例如名字libxcb-icccm.so.4对应的库就是libxcb-icccm4

最后那个数字就是版本号。

原文里面有0,1,4等。

安装的时候可以一次性安装。

结论

不要用WSL……直接装原生。

posted @ 2023-03-31 09:31  大福是小强  阅读(139)  评论(0编辑  收藏  举报  来源