在Linux上使用PyQt5时,出现qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
错误,通过调试发现是libxcb-xinerama0
丢失,安装libxcb-xinerama0
即可解决:
sudo apt install --reinstall libxcb-xinerama0
测试环境:Ubuntu 20.04 + Python 3.8 + PyQt5 5.15.0
下面介绍具体过程和解决办法。
运行PyQt5程序时,出现如下错误:
$ python3 tms.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.
发现是Qt加载插件出现问题,通过设置QT_DEBUG_PLUGINS=1
,可以查看Qt的插件加载信息。
所以先设置环境变量:
export QT_DEBUG_PLUGINS=1
再次运行程序时,会打印出很多信息,重点是最后一段:
$ python3 tms.py
QFactoryLoader::QFactoryLoader() checking directory path "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqeglfs.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"eglfs"
]
},
"archreq": 0,
"className": "QEglFSIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqlinuxfb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"linuxfb"
]
},
"archreq": 0,
"className": "QLinuxFbIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqminimal.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqminimal.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"minimal"
]
},
"archreq": 0,
"className": "QMinimalIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqminimalegl.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"minimalegl"
]
},
"archreq": 0,
"className": "QMinimalEglIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqoffscreen.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"offscreen"
]
},
"archreq": 0,
"className": "QOffscreenIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqvnc.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqvnc.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"vnc"
]
},
"archreq": 0,
"className": "QVncIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-egl.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-egl.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"wayland-egl"
]
},
"archreq": 0,
"className": "QWaylandEglPlatformIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("wayland-egl")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-generic.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-generic.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"wayland"
]
},
"archreq": 0,
"className": "QWaylandIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("wayland")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-xcomposite-egl.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-xcomposite-egl.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"wayland-xcomposite-egl"
]
},
"archreq": 0,
"className": "QWaylandXCompositeEglPlatformIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("wayland-xcomposite-egl")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-xcomposite-glx.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwayland-xcomposite-glx.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"wayland-xcomposite-glx"
]
},
"archreq": 0,
"className": "QWaylandXCompositeGlxPlatformIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("wayland-xcomposite-glx")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwebgl.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqwebgl.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"webgl"
]
},
"archreq": 0,
"className": "QWebGLIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("webgl")
QFactoryLoader::QFactoryLoader() looking at "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so"
Found metadata in lib /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"xcb"
]
},
"archreq": 0,
"className": "QXcbIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
Cannot load library /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)
QLibraryPrivate::loadPlugin failed on "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)"
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.
已放弃 (核心已转储)
这儿单独看下最后一段:
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
Cannot load library /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)
QLibraryPrivate::loadPlugin failed on "/home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录)"
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.
已放弃 (核心已转储)
它提示无法加载libqxcb.so
,原因是libxcb-xinerama.so.0: 无法打开共享对象文件: 没有那个文件或目录
,也就是说libxcb-xinerama.so.0
共享库丢失,导致无法加载libqxcb.so
。通过ldd指令查看libqxcb.so
的动态链接库,可以看到libxcb-xinerama.so.0 => not found
,完整信息如下:
$ ldd /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so
linux-vdso.so.1 (0x00007fff3e530000)
libQt5XcbQpa.so.5 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libQt5XcbQpa.so.5 (0x00007f6b24dc9000)
libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f6b24d6f000)
libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f6b24cb0000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6b24c94000)
libQt5Gui.so.5 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libQt5Gui.so.5 (0x00007f6b24360000)
libQt5DBus.so.5 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libQt5DBus.so.5 (0x00007f6b240d2000)
libQt5Core.so.5 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libQt5Core.so.5 (0x00007f6b238df000)
libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f6b23857000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6b23834000)
libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f6b2382f000)
libxcb-icccm.so.4 => /lib/x86_64-linux-gnu/libxcb-icccm.so.4 (0x00007f6b23828000)
libxcb-image.so.0 => /lib/x86_64-linux-gnu/libxcb-image.so.0 (0x00007f6b23621000)
libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f6b2361c000)
libxcb-keysyms.so.1 => /lib/x86_64-linux-gnu/libxcb-keysyms.so.1 (0x00007f6b23617000)
libxcb-randr.so.0 => /lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x00007f6b23604000)
libxcb-render-util.so.0 => /lib/x86_64-linux-gnu/libxcb-render-util.so.0 (0x00007f6b235fd000)
libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f6b235ee000)
libxcb-shape.so.0 => /lib/x86_64-linux-gnu/libxcb-shape.so.0 (0x00007f6b235e7000)
libxcb-sync.so.1 => /lib/x86_64-linux-gnu/libxcb-sync.so.1 (0x00007f6b235dd000)
libxcb-xfixes.so.0 => /lib/x86_64-linux-gnu/libxcb-xfixes.so.0 (0x00007f6b235d3000)
libxcb-xinerama.so.0 => not found
libxcb-xkb.so.1 => /lib/x86_64-linux-gnu/libxcb-xkb.so.1 (0x00007f6b235b5000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f6b2358b000)
libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f6b23574000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f6b23437000)
libxkbcommon-x11.so.0 => /lib/x86_64-linux-gnu/libxkbcommon-x11.so.0 (0x00007f6b2342c000)
libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f6b233ea000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6b233e4000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6b23203000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6b230b2000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6b23097000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6b22ea5000)
libxcb-xinerama.so.0 => not found
libgthread-2.0.so.0 => /lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f6b22ea0000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f6b22d77000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f6b22d47000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f6b22d3e000)
libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f6b22d06000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f6b22cb5000)
libicui18n.so.56 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libicui18n.so.56 (0x00007f6b2281c000)
libicuuc.so.56 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libicuuc.so.56 (0x00007f6b22462000)
libicudata.so.56 => /home/txfly/PycharmProjects/TMS/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/../../lib/libicudata.so.56 (0x00007f6b20a7f000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6b25326000)
libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f6b209c7000)
libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f6b20993000)
libxcb-util.so.1 => /lib/x86_64-linux-gnu/libxcb-util.so.1 (0x00007f6b2078d000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f6b20785000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f6b2077d000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f6b2070a000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f6b2065d000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f6b20643000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6b20636000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f6b2060f000)
liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f6b205ee000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f6b204d0000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f6b204ad000)
解决办法
通过重新安装libxcb-xinerama0
即可:
sudo apt install --reinstall libxcb-xinerama0
如果是其它共享库not found,安装对应的软件包即可。
版权声明:本文为「txfly」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://www.jianshu.com/p/b51008566134