即使找到Qt平台插件,也无法" " "xcb"加载



这个问题在Stack Overflow中被问了好几次。我在几次讨论中尝试了方法,但没有奏效。所以我用自定义Qt构建的OpenCV库无法正常工作:

import cv2
img = cv2.imread("IMAGE_PATH")
cv2.imshow("frame", img)
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, minimal, minimalegl, offscreen, vnc, xcb.
Aborted (core dumped)

我试过什么

  • 我尝试设置export QT_DEBUG_PLUGINS=1并执行一个具有OpenCV绘制图像的Python脚本。错误信息:
QFactoryLoader::QFactoryLoader() checking directory path "/home/w/.conda/envs/py36/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqeglfs.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"eglfs"
]
},
"className": "QEglFSIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqminimal.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqminimal.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"minimal"
]
},
"className": "QMinimalIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqminimalegl.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"minimalegl"
]
},
"className": "QMinimalEglIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqoffscreen.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"offscreen"
]
},
"className": "QOffscreenIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqvnc.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqvnc.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"vnc"
]
},
"className": "QVncIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/w/.conda/envs/py36/plugins/platforms/libqxcb.so"
Found metadata in lib /home/w/.conda/envs/py36/plugins/platforms/libqxcb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"xcb"
]
},
"className": "QXcbIntegrationPlugin",
"debug": false,
"version": 329991
}

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/w/.conda/envs/py36/bin/platforms" ...
Cannot load library /home/w/.conda/envs/py36/plugins/platforms/libqxcb.so: (/home/w/.conda/envs/py36/plugins/platforms/../../lib/libQt5XcbQpa.so.5: symbol _ZN11QFontEngine14bitmapForGlyphEj6QFixedRK10QTransform, version Qt_5_PRIVATE_API not defined in file libQt5Gui.so.5 with link time reference)
QLibraryPrivate::loadPlugin failed on "/home/w/.conda/envs/py36/plugins/platforms/libqxcb.so" : "Cannot load library /home/w/.conda/envs/py36/plugins/platforms/libqxcb.so: (/home/w/.conda/envs/py36/plugins/platforms/../../lib/libQt5XcbQpa.so.5: symbol _ZN11QFontEngine14bitmapForGlyphEj6QFixedRK10QTransform, version Qt_5_PRIVATE_API not defined in file libQt5Gui.so.5 with link time reference)"
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, minimal, minimalegl, offscreen, vnc, xcb.
Aborted (core dumped)
  • 我尝试~/.bashrc文件中设置export LD_LIBRARY_PATH=/opt/Qt5.14.0/5.14.0/gcc_64/lib:$LD_LIBRARY_PATH但没有解决。
  • 我尝试重新安装Qt5但没有用。
  • 我尝试按照人们的说法使用ldd,但我不确定我应该寻找什么信息。

如果相关

  • 首先,如果相关,我在 Ubuntu 16.04 上安装了 Anaconda,并在安装了多个库py36创建了一个通用的 Python 环境名称。我尝试运行conda list,以下是一些软件包:
...
pyqt                      5.9.2            py36h05f1152_2  
qt                        5.9.7                h5867ecd_1
vtk                       8.2.0           py36haa4764d_200
...

老实说,我不知道这些库是什么时候安装的(当我安装其他软件包时,它们会自动安装。

  • 接下来,我下载了Qt离线安装程序并安装到/opt/Qt-5.14.0
  • 接下来,我使用以下设置编译了 OpenCV 3.4.9。我走得很好,没有任何错误。(之后,我在 conda 环境中设置符号链接cv2.so,以指向/opt中构建的 OpenCV 库。
cmake -D CMAKE_BUILD_TYPE=RELEASE 
-D CMAKE_INSTALL_PREFIX=/opt/OpenCV/opencv-3.4.9 
-D CMAKE_PREFIX_PATH="/opt/Qt5.14.0/5.14.0/gcc_64/lib/cmake;/opt/vtk-8.2.0/lib/cmake;/opt/g2o/lib/cmake" 
-D OPENCV_EXTRA_MODULES_PATH=/home/w/OpenCV/opencv-3.4.9/opencv_contrib-3.4.9/modules 
-D PYTHON3_EXECUTABLE=/home/w/.conda/envs/py36/bin/python3 
-D WITH_OPENGL=ON 
-D WITH_V4L=ON 
-D WITH_LIBV4L=ON 
-D WITH_FFMPEG=ON 
-D WITH_VTK=ON 
-D WITH_QT=ON 
-D WITH_GTK=ON 
..

这可能是由缺少库引起的,尽管不一定是其他答案中列出的库。这是您可以自己弄清楚的方法。

QT_DEBUG_PLUGINS=1设置环境变量,然后运行应用程序。这应该提供有关失败原因的更多详细信息。例如,当我使用我的应用程序运行它时,我看到:

qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "/home/david/work/junk/pywebview-test/.venv/lib/python3.10/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/david/work/junk/pywebview-test/.venv/lib/python3.10/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so: (libxcb-cursor.so.0: cannot open shared object file: No such file or directory)"

这意味着链接到所列库的库可能丢失。若要找出确切的路径,请根据您的错误消息运行以下命令替换完整路径:

ldd /home/david/work/junk/pywebview-test/.venv/lib/python3.10/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so

在我的电脑上,这显示了一行:

libxcb-cursor.so.0 => not found

所以我安装了缺少的库:

sudo apt install libxcb-cursor0

安装所有缺少的库后,请尝试再次运行该应用程序。

我在 ubuntu linux 上。 我确保删除任何与 pyqt5 相关的软件包,并使用 pip 冻结 (pip freeze | grep -i qt( 检查它们的存在。

我不确定它是如何解决问题的,但我认为与 pip 加载包存在一些内部冲突。

为了解决已删除的 pyqt 软件包,我改用了sudo apt-get install python3-pyqt5。 这是有效的,因为 pip 尝试从目录中加载 CV2 和 Pyqtpython3/site-packages其中来自 APT-get 的包是从python3/dist-packages加载的,因此冲突得到解决。

我通过研究为什么它与apt-get(dist-packages(一起工作,以及从python解释器内部查看sys.path来推断它。 就我而言,site-packages继续进行dist-packages

错误似乎是库冲突Qt。链接器找不到正确的Qt库(安装在/opt文件夹中(,这是我在 conda 虚拟环境中的自定义构建OpenCV所需的。这是因为虚拟环境中安装了另一个Qt库。这可以通过使用ldd.(抱歉,那是前段时间了,所以我没有输出。

正如预期的那样,通过删除虚拟 conda 环境中所有与 Qt 相关的库,使用Qt构建的OpenCV库(安装在/opt文件夹中(可以正常工作。

对我来说,这解决了这个问题:

sudo apt-get install libxcb-xinerama0

参考: https://forum.qt.io/post/616242

我在 Debian 10 上尝试运行 spyder 时遇到了这个问题。修复了从此处安装 .deb 文件的问题:

https://packages.debian.org/bullseye/amd64/libxcb-util1/download

相关内容

  • 没有找到相关文章

最新更新