Ubuntu16.04下Python程序出现错误qt.qpa.plugin: Could not load the Qt platform plugin xcb解决方法

问题描述

我在运行一个使用Pyqt5库的Python程序时,出现报错:

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, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

解决方案

出现这个问题的可能原因主要是Qt动态链接库的问题,从问题描述来看,应该是libxcb.so库链接不正确,并且说的是“能够找到,但是无法加载”。

尝试方法

你可以先尝试安装一些依赖,看下能不能解决:

sudo apt-get install libxkbcommon-x11-0

最终成功方案

关于这个问题的解决方案,网上有很多都是讲解如何设置链接库,或者如何将platform/plugins等地址加入到环境变量中,我试了一下都没用。

最终经过另一番搜索,突然发现这个链接中有人提到可以在你运行你的Python可执行文件之前先在终端执行下面命令:

export QT_DEBUG_PLUGINS=1

然后再执行你的可执行文件,这个时候就会列出详细的报错原因。

果不其然,此时我再运行程序,列出了一个详细的错误原因的线索:

error while loading shared libraries: libxcb-xinerama.so: cannot open shared object file: No such file or directory

也就是当加载libxcb.so库时,还需要加载libxcb-xinerama库,于是我就安装了这个库:

sudo apt-get install libxcb-xinerama0

然后再执行可执行文件,OK,成功~

【参考】

  1. https://blog.csdn.net/jiguangfan/article/details/86490160
  2. https://forum.qt.io/topic/111553/solved-qt-qpa-plugin-could-not-find-the-qt-platform-plugin-xcb-in
  3. http://www.manongjc.com/article/44387.html
  4. https://stackoverflow.com/questions/17106315/failed-to-load-platform-plugin-xcb-while-launching-qt5-app-on-linux-without#
  5. https://github.com/therecipe/qt/issues/775

你可能感兴趣的:(Python)