这个问题在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 \
..