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

21

58

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?

Aphonic answered 18/6, 2021 at 13:57 Comment(0)
P
67

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

Preoccupancy answered 5/4, 2023 at 15:53 Comment(1)
My original solution used for l in $(cat) to loop over and inspect the xcb libs. It's probably better to use while read lib since $(cat) might not work cleanly, see https://mcmap.net/q/331576/-pipe-a-list-of-strings-to-for-loopPreoccupancy
V
27

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!

Vickivickie answered 7/12, 2022 at 15:49 Comment(4)
I tried to implement this on my Dockerfile and got a new error WebEngineContext is used before QtWebEngineQuick::initialize() or OpenGL context creation failed. [1:1:0922/214114.391383:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180. "/usr/local/lib/python3.11/site-packages/PySide6/Qt/plugins/platforms/libqoffscreen.so" unloaded libraryBeaufert
@Adam, Thank you for letting me know. Actually, I didn't use this on the Dockerfile but now I know that it won't work in that way, thanksVickivickie
what ended up working for me was a combination of your suggestion and one more line, so I had to have both ENV QT_QPA_PLATFORM=offscreen and ENV QTWEBENGINE_DISABLE_SANDBOX=1. Thanks for getting me halfway there!Beaufert
QT_QPA_PLATFORM=offscreen works, but now my app does not appear on the screen at all.Philemon
P
21

I solved this problem by running this command in console

sudo apt install libxcb-xinerama0

The original link here

Prodrome answered 21/5, 2022 at 4:51 Comment(0)
J
11

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
Jubilee answered 14/8, 2023 at 3:46 Comment(0)
S
5

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

sudo yum install xcb-util*
Spindlelegs answered 27/7, 2022 at 14:12 Comment(0)
N
4

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.

Nicias answered 11/10, 2022 at 5:50 Comment(0)
N
4

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

pip uninstall PyQt5

Nassir answered 8/2, 2023 at 5:27 Comment(0)
B
3

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.

Bricabrac answered 6/5, 2023 at 20:57 Comment(0)
L
2

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.

Longsufferance answered 7/8, 2022 at 19:17 Comment(1)
opencv-python was indeed the culprit for me. As soon as I installed it, I started facing the error from OP. Unfortunately, first installing pyqt through conda, and only after that installing opencv-python through pip, did not solve the issue for me. What solved the issue is: 1) first install pyqt through conda 2) now do conda install -c conda-forge opencv 3) finally: pip install opencv-pythonProsper
V
2

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

Voorhees answered 25/9, 2023 at 14:41 Comment(0)
S
1

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

I solved it by installing libxcb-xinerama0.

sudo apt install libxcb-xinerama0
Seductress answered 30/5, 2022 at 10:18 Comment(0)
C
1

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

sudo dnf install xcb-util*
Civility answered 3/11, 2022 at 16:58 Comment(0)
U
1

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
Unwished answered 23/4, 2023 at 16:58 Comment(0)
C
1

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.

Choosy answered 20/7, 2023 at 6:31 Comment(0)
I
1

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
Illustrational answered 19/11, 2023 at 16:32 Comment(0)
R
1

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!

Raisaraise answered 29/1 at 8:55 Comment(0)
Z
0

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
Zoophilia answered 5/12, 2023 at 20:37 Comment(0)
C
0

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.

Characterize answered 15/12, 2023 at 7:51 Comment(0)
M
0

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
Mignonne answered 19/12, 2023 at 5:15 Comment(1)
This didn't make a difference in my caseCocker
T
0
export QT_QPA_PLATFORM=wayland

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

Tapes answered 20/3 at 10:44 Comment(0)
D
-2
export QT_QPA_PLATFORM=offscreen 

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

Daina answered 3/11, 2023 at 6:24 Comment(1)
Why did you copy an already existing post?Vickivickie

© 2022 - 2024 — McMap. All rights reserved.