[Ubuntu] QT program could not find or load the Qt platform plugin “xcb” in “error solution

Problem Description:

See below:
insert image description here

import matplotlib.pyplot as plt
import cv2
img=cv2.imread('img_path')###读入单张图片

b,g,r=cv2.split(img) #原图的bgr三个通道分离
img_rgb=cv2.merge([r,g,b])#rgb顺序显示的合成

plt.figure()
plt.subplot(331),plt.imshow(img),plt.title("cat_bgr")

plt.subplot(337),plt.imshow(img_rgb),plt.title("cat_rgb")
 
plt.show()

Run the above code, the blogger mainly calls matplotlibthe function drawing, search * "This application failed to start because it could not find or load the Qt platform plugin "xcb"* on the Internet, and get the following solution:

method one:

Cause analysis:
The matplotlib version is not compatible

Solution:
first uninstall the original matplotlib and then reinstall it

reference:

pip uninstall matplotlib
pip install matplotlib

Method Two:

Cause Analysis:

We want to call matplotlibthe function drawing, but the error message is that it could not find or load the Qt platform plugin “xcb” in " ",
so consider that the versions of Qt and matplotlib are not compatible.

Solution:
Uninstall QT and matplotlib and reinstall

reference:

conda uninstall qt
conda uninstall matplotlib
conda install qt
conda install matplotlib

Method three:

Cause analysis:
There is a lack of corresponding files in the platforms folder, try to manually switch by yourself, and find the platforms file in the Qt installation directory, which is a sub-file under the plugins file, and put the .dll file in your own folder , to run.

The blogger did not try this solution, because it involves the movement of the underlying dependent files, it is easy to cause problems due to missing some files, and because the conda environment was messy at the time, the Qt installation directory could not be found, so this solution was abandoned. It is not recommended to try to use

Method four (probably the most common case):

Precondition:
Command line input qtcreatorgenerates an error:

This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

If it qtcreatorcan be started normally, this is not the case. The normal start is as shown in the figure below:
insert image description here
Solution:
1. Input

sudo gedit ~/.bashrc

In the last line add:

export QT_DEBUG_PLUGINS=1

The function of this step is that you can see the error message during the qt startup process
2. Run qtcreator, and get the running process on the command line, as follows:

Got keys from plugin meta data ("vnc")
QFactoryLoader::QFactoryLoader() looking at "/opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so"
Found metadata in lib /opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so, metadata=
{
    
    
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
    
    
        "Keys": [
            "xcb"
        ]
    },
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 330240
}


Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/Qt5.10.0/Tools/QtCreator/bin/platforms" ...
Cannot load library /opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version `Qt_5_PRIVATE_API' not found (required by /opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so))
QLibraryPrivate::loadPlugin failed on "/opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so: (/usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version `Qt_5_PRIVATE_API' not found (required by /opt/Qt5.10.0/Tools/QtCreator/lib/Qt/plugins/platforms/libqxcb.so))"
This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Reinstalling the application may fix this problem.
Aborted (core dumped)

3. The reason is libqxcb.so, cd to /opt/Qt5.10.0/5.10.0/gcc_64/plugins/platforms, run the command ldd libqxcb.so, view the related content, as follows:

./libqxcb.so: /usr/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: version `Qt_5_PRIVATE_API' not found (required by ./libqxcb.so)
./libqxcb.so: /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: version `Qt_5_PRIVATE_API' not found (required by ./libqxcb.so)
./libqxcb.so: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.10' not found (required by ./libqxcb.so)
./libqxcb.so: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5' not found (required by ./libqxcb.so)

You can see that the problem is: ‘Qt_5_PRIVATE_API’ not found
4. You need to add environment variables, as follows:

export LD_LIBRARY_PATH=/opt/Qt5.10.0/5.10.0/gcc_64/lib:$LD_LIBRARY_PATH

5. Command line input qtcreator, successful operation

Method five:

Idea 1:
Set the environment variable export QT_DEBUG_PLUGINS=1

Run to see the process of loading the QT program, and see detailed error information.
The last part looks like this:

Found metadata in lib /usr/lib64/qt5/plugins/platforms/libqxcb.so, metadata=
{
    
    
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
    
    
        "Keys": [
            "xcb"
        ]
    },
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 329218
}
QLibraryPrivate::loadPlugin failed on "/usr/lib64/qt5/plugins/platforms/libqxcb.so" : "Cannot load library /usr/lib64/qt5/plugins/platforms/libqxcb.so: (/lib64/libQt5XcbQpa.so.5: symbol _ZNK11QFontEngine6handleEv, version Qt_5_PRIVATE_API not defined in file libQt5Gui.so.5 with link time reference)"
This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, xcb, xcb.

Reinstalling the application may fix this problem.

Copy libQt5XcbQpa.so, libQt5DBus.so.5 to the running directory.

Idea 2:
Copy the platforms directory under the plugins directory under qt to the executable directory, which is at the same level as the executable program (must be at the same level)

This method is the same as method three

Method six:

解决qt.qpa.plugin: Could not find the Qt platform plugin “xcb“ in ““

Method seven (also my final solution):

Idea:
Recreate a conda environment:

conda create -n env_name python=3.7

Installation matplotlibpackage:

pip install matplotlib

Solved successfully!

Reference link:
1. [SOLVED] qt.qpa.plugin: Could not find the Qt platform plugin “xcb” in “”

Guess you like

Origin blog.csdn.net/weixin_48936263/article/details/124655575