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

导读:本篇文章讲解 Ubuntu16.04下Python程序出现错误qt.qpa.plugin: Could not load the Qt platform plugin xcb解决方法,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

问题描述

我在运行一个使用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,成功~

其他还可能能安装的库包括:

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

其他可能问题

qt.qpa.xcb: could not connect to display :0

一般是你连接远程服务器安装一些需要用到图像化界面的软件时会碰到,例如我在安装mayavi就碰到这个问题。
解决方案
首先确认你的ssh连接开启了X11 Forwarding功能,即你在终端执行xclock是否会在显示器上显示一个小时钟;
如果不能可能需要设置一下DISPLAY变量:

export DISPLAY=:0.0

可能需要加上你的电脑IP等信息,具体请查询下;
参考:https://blog.csdn.net/qq_34907927/article/details/116597908

还有可能需要安装:

sudo apt-get install freeglut3-dev

或者降低你的PyQt版本和python-opencv版本:

pip install opencv-python==4.3.0.36 PyQt5==5.15.2

具体到底是上面哪些操作起了作用我也不是很确定,反正最后我是一通操作后成功了。

【参考】

  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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/121226.html

(0)
seven_的头像seven_bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!