IgNite
IgNite

Reputation: 792

Could not load the Qt platform plugin "xcb" in "" even though it was found

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

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)

If relevant

 ...
 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.)

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 \
..

Upvotes: 19

Views: 46655

Answers (6)

Joeytje50
Joeytje50

Reputation: 19112

Even though I have no idea why this works, after trying everything else on the internet, simply deleting the libqxcb.so file from the pyqt plugins solved the issue for me. If anyone knows why this fixed the issue for me (while reinstalling things did not), please let me know.

The way to do this is to go to the folder mentioned in the error message, go to the platforms subfolder, and then delete the libqxcb.so file in there. For me, the message was Could not load the Qt platform plugin "xcb" in "/home/MyUsername/.local/lib/python3.10/site-packages/cv2/qt/plugins" even though it was found., so I deleted /home/MyUsername/.local/lib/python3.10/site-packages/cv2/qt/plugins/platforms/libqxcb.so. If you, like me, can't find any other solutions to this issue, you could try this. Or, to be more safe, move it to some backup location so that you could place it back if something else breaks more catastrophically.

Upvotes: 4

David Lechner
David Lechner

Reputation: 1814

It is likely caused by a missing library, although not necessarily one listed in the other answers. Here is how you can figure it out for yourself.

Set the environment variable QT_DEBUG_PLUGINS=1 and then run your application. This should give more detailed information on why it failed. For example when I ran it with my app, I saw:

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)"

This means a library linked to the one listed is probably missing. To find out which one exactly, run the following replacing the full path based on your error message:

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

On my computer, this showed a line with:

libxcb-cursor.so.0 => not found

So I installed the missing library with:

sudo apt install libxcb-cursor0

Once all missing libraries are installed, try running the app again.

Upvotes: 24

Ohumeronen
Ohumeronen

Reputation: 2086

I had this issue on Debian 10 trying to run spyder. Fixed the issue installing the .deb file from here:

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

Upvotes: 0

Shriman Keshri
Shriman Keshri

Reputation: 179

For me this resolved the issue:

sudo apt-get install libxcb-xinerama0

Reference: https://forum.qt.io/post/616242

Upvotes: 3

Gal Zafar
Gal Zafar

Reputation: 61

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

Upvotes: 6

IgNite
IgNite

Reputation: 792

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.

Upvotes: 5

Related Questions