Bak Seongho
Bak Seongho

Reputation: 151

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found."

I have installed gqcnn, Pyrep and autolab_core. After that, I executed the code that my coworker wrote and, it ran fine on his computer.

However, I cannot run the code. The occurred error was

python3.7/site-packages/cv2/qt/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/bak/anaconda3/envs/pyrep/lib/python3.7/site-packages/cv2/qt/plugins/platforms/libqxcb.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/lib/python3.7/site-packages/cv2/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
}


In /home/bak/anaconda3/envs/pyrep/lib/python3.7/site-packages/cv2/qt/plugins/platforms/libqxcb.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
"The plugin '/home/bak/anaconda3/envs/pyrep/lib/python3.7/site-packages/cv2/qt/plugins/platforms/libqxcb.so' uses incompatible Qt library. (5.15.0) [release]" 
         not a plugin
QFactoryLoader::QFactoryLoader() checking directory path "/home/bak/anaconda3/envs/pyrep/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/bak/anaconda3/envs/pyrep/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqminimal.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqvnc.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqxcb.so"
Found metadata in lib /home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/bin/platforms" ...
Cannot load library /home/bak/anaconda3/envs/pyrep/plugins/platforms/libqxcb.so: (/home/bak/anaconda3/envs/pyrep/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/bak/anaconda3/envs/pyrep/plugins/platforms/libqxcb.so" : "Cannot load library /home/bak/anaconda3/envs/pyrep/plugins/platforms/libqxcb.so: (/home/bak/anaconda3/envs/pyrep/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 "/home/bak/anaconda3/envs/pyrep/lib/python3.7/site-packages/cv2/qt/plugins" 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.

If you want to see the full error in detail, please see here. '/pyrep/' in above is my anaconda environment name.

It seems to be caused by qt. But I cannot fix this problem.

What should I do to solve this problem?

Upvotes: 11

Views: 39739

Answers (8)

Musabbir Arrafi
Musabbir Arrafi

Reputation: 1885

This is an opencv dependency issue with pyQt5. pyQt5 doesn't support opencv-contrib-python fully. I was building an app with mediapipe, opencv and pyQt5 modules and struggled with issues for days. I found that this dependency problem can't be solved fully by just uninstalling opencv-contrib-python and installing opencv-python-headless. This and all other solutions that I found regarding this issue are just a temporary fix and don't go well if you want to deploy the app or script on a new machine.

I found the best solution is to use pyQt6. pyQt6 supports opencv-contrib-python fully. So, just uninstall everything of pyQt5 and install pyQt6.

This will uninstall every pyQt5 modules:

pip freeze | grep -E '^PyQt5' | awk -F'==' '{print $1}' | xargs pip uninstall -y

then install pyqt6:

pip install pyqt6

Upvotes: 0

ACV
ACV

Reputation: 10562

  1. conda list | grep 'qt'

  2. For each found entry do:

conda remove --force package_name where package_name is the name returned by previous command

Upvotes: 0

mr.loop
mr.loop

Reputation: 1005

Solved my issue through https://github.com/NVlabs/instant-ngp/discussions/300

pip uninstall opencv-python
pip install opencv-python-headless

This seems to have been a problem with the cv2 Python package and how it loops in Qt

Upvotes: 7

Nick Halden
Nick Halden

Reputation: 49

If you are running this on a machine that has no display/graphical output (e.g. a server), make sure that your script does not call any cv2 functions for graphical output like cv2.namedWindow or cv2.imshow.

Upvotes: 1

Nate River
Nate River

Reputation: 141

I'd like to add something here.

I had this issue, but on debian10, and none of the solutions mentioned helped. What did help, was to realize that, in my case, pip installed version 5.15.2 of pyqt5 by default. However, here (https://repology.org/project/python:pyqt5/versions) it is stated that the version of pyqt5 recommended for debian10 is 5.11.3.

When I reinstalled pyqt5 with that version:

$ pip3 install PyQt5==5.11.3

the issue was fixed. The point, is that it may be a good idea to check:

  • Which version of pyqt5 is installed by pip by default
  • Which version of pyqt5 is recommended for one's OS/distro

Upvotes: 4

UdaraWanasinghe
UdaraWanasinghe

Reputation: 2852

This issue occurs when you use opencv with pyqt5. It looks like qt plugin internally used by opencv is not compatible with pyqt5. Just unset environment variable QT_QPA_PLATFORM_PLUGIN_PATH after import cv2 statement.

import os

os.environ.pop("QT_QPA_PLATFORM_PLUGIN_PATH")

You could also update the platform plugin path after importing opencv

import os

os.environ.update({"QT_QPA_PLATFORM_PLUGIN_PATH": "/home/udara/anaconda3/envs/research-headless/lib/python3.8/site-packages/PyQt5/Qt5/plugins/xcbglintegrations/libqxcb-glx-integration.so"})

Note that this will make opencv window functions unusable. If you want to use them, you have to build opencv from source without the qt plugin. You could build the opencv with gtk plugin instead of qt.

References https://forum.qt.io/post/654289

Upvotes: 16

Bak Seongho
Bak Seongho

Reputation: 151

Finally, I find the solution! https://github.com/stepjam/PyRep/issues/76

The problem was loading Qt in the conda environment.

When I typed qmake -version, the terminal window showed me the qt in anaconda. After I followed the first answer at the above URL, I can fix the problem.

Upvotes: 4

shredEngineer
shredEngineer

Reputation: 460

This may be related to a similar error message.

I just came across this problem, in Ubuntu 20.04, Python 3.8, while trying to use matplotlib_backend_qtquick.

This answer in the mentioned thread solved it for me: https://askubuntu.com/a/1069502

Upvotes: 3

Related Questions