CuriousPan
CuriousPan

Reputation: 1299

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

I'm using Ubuntu 20.04 via Oracle VM Virtual Box and I faced exactly the same error as all other people.

After building Qt6 source code using official Qt manual, I'm trying to run different projects to test if everything works properly. Console-type projects build and run properly. There are no errors. Unfortunately, when I try to run a widget-type application, it fails with the well-known error:

t.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, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

My colleague, who has Qt6 working properly on his Ubuntu, saw that I don't have libqxcb.so in the .../qtbase/plugins/platforms, and shared it with me.

Unfortunately, it didn't help much. Only the error message has changed a bit: it says that plugin was found, but couldn't be used.

The below command had no impact:

sudo apt install libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0

Also, there's more verbose output with environmental variable QT_DEBUG_PLUGINS=1:

QFactoryLoader::QFactoryLoader() checking directory path "/home/curiouspan/qt6-build/qtbase/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqeglfs.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqeglfs.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "eglfs"
        ]
    },
    "archreq": 1,
    "className": "QEglFSIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("eglfs")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqlinuxfb.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqlinuxfb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "linuxfb"
        ]
    },
    "archreq": 1,
    "className": "QLinuxFbIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("linuxfb")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimal.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimal.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 1,
    "className": "QMinimalIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("minimal")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimalegl.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqminimalegl.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimalegl"
        ]
    },
    "archreq": 1,
    "className": "QMinimalEglIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("minimalegl")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqoffscreen.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqoffscreen.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 1,
    "className": "QOffscreenIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("offscreen")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqvnc.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqvnc.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "vnc"
        ]
    },
    "archreq": 1,
    "className": "QVncIntegrationPlugin",
    "debug": true,
    "version": 393728
}


Got keys from plugin meta data QList("vnc")
QFactoryLoader::QFactoryLoader() looking at "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so"
Found metadata in lib /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "archreq": 0,
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 393728
}


Got keys from plugin meta data QList("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/curiouspan/QtTestProjects/build-WidgetTestApp-Own_Desktop-Debug/platforms" ...
Cannot load library /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so: (libQt6XcbQpa.so.6: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so" : "Cannot load library /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so: (libQt6XcbQpa.so.6: cannot open shared object file: No such file or directory)"
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, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

It shows that libQt6XcbQpa.so.6 file is missing.

After running ldd /home/curiouspan/qt6-build/qtbase/plugins/platforms/libqxcb.so to show the dependencies, I got the following output:

linux-vdso.so.1 (0x00007fffc8770000)
    libQt6XcbQpa.so.6 => not found
    libQt6Gui.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6Gui.so.6 (0x00007f0873306000)
    libQt6Core.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6Core.so.6 (0x00007f087295d000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f087277c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f087258a000)
    libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x00007f0872573000)
    libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f0872436000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0872430000)
    libQt6DBus.so.6 => /home/curiouspan/qt6-build/qtbase/plugins/platforms/../../lib/libQt6DBus.so.6 (0x00007f0872262000)
    libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f087222e000)
    libOpenGL.so.0 => /lib/x86_64-linux-gnu/libOpenGL.so.0 (0x00007f0872202000)

So this file is really missing. What can be the potential problem, and how do I fix it?

Upvotes: 79

Views: 207966

Answers (25)

Divyajyoti
Divyajyoti

Reputation: 43

None of the answers above worked for me. This is what I tried and it worked.

sudo apt install libxcb-xinerama0 libxcb-xkb1 libxcb1 libxcb-glx0 libqt5gui5 libqt5core5a libqt5widgets5 qt5-qmake qtbase5-dev

Upvotes: 1

Michael Lee
Michael Lee

Reputation: 336

For debian 12 with Xfce4 as default DE, apt install -y libqt5gui5 solves the problem.

Upvotes: 0

Young-Jae Choi
Young-Jae Choi

Reputation: 11

For conda users,

conda install xcb-util xcb-util-cursor xcb-util-image xcb-util-keysyms xcb-util-renderutil xcb-util-wm

worked for me.

Upvotes: 0

Ershat
Ershat

Reputation: 76

check whether libQt6XcbQpa.so.6 is existed in you appfolder/lib.

  • if not found, then check your deploy script, like qmake or cmake.
    qt_generate_deploy_script in cmake can automatically copy it.
  • if libQt6XcbQpa.so.6 existed in appfolder/lib, then check yout executable RUNPATH or RPATH using below command:
readelf -d <executable> | grep -E 'RUNPATH|RPATH'

it should contain like $ORIGIN;$ORIGIN/../lib.
if it does not contain, then you should check you cmake.

Upvotes: 0

faraidoon123
faraidoon123

Reputation: 71

I'm working with Linux Mint 21 and using VSCode as my editor. I was just trying to run a simple GUI application when I encountered an issue.

I have installed Pyenv and was able to resolve the problem by running the following command:

sudo apt install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev

This command installs several development libraries and dependencies that are required by some Python packages. By running this command, I was able to fix the issue I was facing.

Upvotes: 5

Dickson Adanya
Dickson Adanya

Reputation: 1

export QT_QPA_PLATFORM=wayland

Adding the above export assignment works on Wayland in Ubuntu Mantic OS.

Upvotes: 0

Tuananhcwrs
Tuananhcwrs

Reputation: 1129

I solved this problem by running this command in console

sudo apt install libxcb-xinerama0

The original link here

Upvotes: 23

WangJewell
WangJewell

Reputation: 11

first, echo $QT_QPA_PLATFORM, to see if it is xcb second, locate where the qt plugins is, such as /anaconda3/envs/envsam/lib/python3.10/site-packages/cv2/qt/plugins/platforms ls, then we rm libqxcb.so which will solve the problem.Hope this will work for you all!

Upvotes: 1

Burnleydev
Burnleydev

Reputation: 21

After a fresh installation of Qt Creator, I met the same issue.

I solved it by installing libxcb-xinerama0.

sudo apt install libxcb-xinerama0

Upvotes: 2

user1953366
user1953366

Reputation: 1621

export QT_QPA_PLATFORM=offscreen 

This fixed, as it is written in the link provided by OP.

Upvotes: -3

NilaknaW
NilaknaW

Reputation: 11

I was using OpenCV in a Python virtual environment in WSL. For me, this error was fixed after running this command.

sudo apt install xcb

Upvotes: 1

zheng shuo
zheng shuo

Reputation: 1

If you use SSH to remotely operate the Linux server and run the GUI program, this may be an environmental variable problem.Run your program with sudo -E instead of sudo,it will retain your environment variables and increase permissions at the same time. Maybe you need to execute twice.

 sudo -E /path/to/your/program

Suggest using MobaXterm, which provides GUI callback support.

Upvotes: 0

Amir Soofi
Amir Soofi

Reputation: 386

For me this error was due to a mismatch between python PyQt5 and Ubuntu QT6, which I solved via:

pip uninstall pyqt5
sudo apt install qt6-base-dev
pip install pyqt6

Upvotes: 0

Sanderson Coelho
Sanderson Coelho

Reputation: 41

I'm using opencv with PyQt5, and this did work for me:

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

Upvotes: 2

roshambo
roshambo

Reputation: 347

My solution to this was to set the appropriate DISPLAY variable. Specifically, export DISPLAY=0.0 fixed the issue. The issue disappeared after that, curiously...

Upvotes: 2

Thảo Dương
Thảo Dương

Reputation: 359

I solved this problem by installing PyQt5 dependences

sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev

Upvotes: 19

W.Perrin
W.Perrin

Reputation: 4725

As for me, the platforms directory is absent from the directory qrelease. Just copy it from the Qt installing directory and the error will be gone.

Upvotes: 1

Megacier
Megacier

Reputation: 442

opencv-python now uses Qt6 (at least at version 4.7.0.72). Installing Qt6 solved it for me

sudo apt install qt6-base-dev

Upvotes: 1

Rizzer
Rizzer

Reputation: 1043

For the Qt 6.5.0 release, the missing library was libxcb-cursor.so.0, resolved with

sudo apt install libxcb-cursor0

With that, the sample widget and gui projects from QtCreator run correctly built with Qt 6.5.0. libxcb-cursor.so.0 wasn't previously needed for Qt 6.4.0.

I identified the missing library with this shell code

for l in /path/to/Qt/6.5.0/gcc_64/lib/*.so; do
  echo $l; objdump -p $l | grep NEEDED | sed "s/^/\t"/;
 done | grep xcb | awk '{print $2}' \
| while read lib; do echo $lib; dlocate $lib; done

This scans all the install Qt libraries, extracts their required dependency libraries related to xcb, then prints which debian package provides each libxcb* library. On my system it reported a debian package for each libxcb*.so library except libxcb-cursor.so.0

Upvotes: 79

zhendong liu
zhendong liu

Reputation: 61

you can try delete pyqt5. I have successed using this method.

pip uninstall PyQt5

Upvotes: 6

Vasyl Lyashkevych
Vasyl Lyashkevych

Reputation: 2232

One of the easiest approaches which helped me,type this in console:

export QT_QPA_PLATFORM=offscreen

More you can read here. I hope it would help you!

Upvotes: 35

p3ch3xcr
p3ch3xcr

Reputation: 11

On Rocky Linux 8.6, this solution also works. Thanks @Ivan Sivak

sudo dnf install xcb-util*

Upvotes: 1

umair mughal
umair mughal

Reputation: 96

For me pip install pyqt6 worked.

My application was running on matplotlib and needed an external GUI. So, I tried to install TK, it didn't worked. On installing pyqt5, it gave me the same error as yours, so I remove it. PyQT6 though worked perfectly. I had also installed libxcb (sudo yum install libxcb), but xcb plugin should not be needed in wayland env.

Upvotes: 4

J B
J B

Reputation: 440

I got this same message for a completely different reason. I had had to recreate a python virtual env from scratch after it wouldn't install tensorflow-gpu due to package inconsistencies. That environment had for many months been working correctly with qt, and I had all the qt lib*.so dependencies correctly installed. My rebuilt environment did now have tensorflow-gpu and no package inconsistencies according to conda, but my program was broken now at runtime with this Qt platform plugin xcb error. It turned out that while rebuilding the env i had installed opencv-python via pip, which installed some various Qt packages specific to opencv and python. But, if I installed qt via conda, before installing opencv-python via pip, then pip did not subsequently install those Qt packages for opencv-python, and the xcb plugin error was now fixed.

Upvotes: 2

Ivan Sivak
Ivan Sivak

Reputation: 7498

If you're on Centos, this solved the problem for me:

sudo yum install xcb-util*

Upvotes: 6

Related Questions