问题
This question is asked several times in Stack Overflow. I tried methods in several discussions but it didn't work. So my OpenCV
library which was built with custom Qt
doesn't work properly:
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)
What I have tried
- I tried setting
export QT_DEBUG_PLUGINS=1
and execute a Python script having OpenCV plotting an image. Error message:
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)
- I tried setting
export LD_LIBRARY_PATH=/opt/Qt5.14.0/5.14.0/gcc_64/lib:$LD_LIBRARY_PATH
in~/.bashrc
file but it didn't solve. - I tried reinstalling
Qt5
but it didn't work. - I tried using
ldd
as people said but I am not so sure what information I should be looking.
If relevant
- First, if relevant, I have Anaconda installed on Ubuntu 16.04 and I created a general Python environment name
py36
where several libraries are installed. I tried runningconda list
and the following are some of the packages:
...
pyqt 5.9.2 py36h05f1152_2
qt 5.9.7 h5867ecd_1
vtk 8.2.0 py36haa4764d_200
...
I honestly didn't know when these libraries are installed (They came installed automatically when I installed other packages.)
- Next, I downloaded Qt offline installer and installed to
/opt/Qt-5.14.0
. - Next, I compiled OpenCV 3.4.9 using the following settings. I went well without any errors. (After that I set symlink
cv2.so
in the conda environment to point to the built OpenCV library in/opt
.)
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 \
..
回答1:
The error seems to be the Qt
library conflict. The linker couldn't find the correct Qt
library (installed in /opt
folder) which is required by my custom built OpenCV
in the conda virtual environment. This is because there is another Qt
library installed in the virtual environment. And this can be found by using ldd
. (Sorry, it was some time ago so I don't have the output.)
As expected, by removing all the Qt-related libraries in the virtual conda environment, the OpenCV
library which was built with Qt
(installed in /opt
folder) works properly as usual.
回答2:
I'm on ubuntu linux.
I made sure to remove any pyqt5 related packages, and checked their existence using pip freeze (pip freeze | grep -i qt
).
I'm not sure how it resolved the problem, but I assume that there is some inner-conflict with pip loading the packages.
to resolve the removed pyqt packages, I used sudo apt-get install python3-pyqt5
instead.
this works because pip tries to load cv2 & pyqt from python3/site-packages
directory, where packages from apt-get are loaded from python3/dist-packages
, and thus the conflict is resolved.
I deduced it from looking into why it worked with apt-get (dist-packages), and from looking at sys.path
inside the python interpreter. in my case site-packages
proceeded dist-packages
来源:https://stackoverflow.com/questions/59809703/could-not-load-the-qt-platform-plugin-xcb-in-even-though-it-was-found