Could not load the Qt platform plugin “xcb“

在Ubuntu20.04中使用PyCharm运行含cv2的代码时遇到Qtplatformpluginxcb加载失败的问题。通过设置环境变量QT_QPA_PLATFORM_PLUGIN_PATH和降低opencv版本至4.1.2.30可暂时解决,但可能在其他程序如labelme中仍报错。真正解决方案是识别并安装缺失的链接库,例如在Ubuntu中是libxcb-xinerama.so.0,可以通过sudoapt-getinstalllibxcb-xinerama0来安装。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Ubuntu20.04在Pycharm运行时出现Could not load the Qt platform plugin "xcb"问题
用mmclassification跑test.py脚本,绘制预测图时出现以下问题:

qt.qpa.plugin: Could not load the Qt platform plugin “xcb” in “/home/taoyang/Software/anaconda3/envs/py37/lib/python3.7/site-packages/cv2/qt/plugins” 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: xcb, eglfs, minimal, minimalegl, offscreen, vnc, webgl.

解决方法如下:
在文件开头输入如下代码,其中的路径为报错代码中的路径后再加一个/platforms

envpath = '/home/taoyang/Software/anaconda3/envs/py37/lib/python3.7/site-packages/cv2/qt/plugins/platforms'
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = envpath


但是有点治标不治本,后面在运行labelme时又会报错,卸载QT5也没用,经过一番寻找终于找到解决方案,就是降低opencv版本:

pip install opencv-python==4.1.2.30
————————————————
版权声明:本文为CSDN博主「carambola_TaoYang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/carambola_/article/details/127176223

另一种方法:

一般出现qt.qpa.plugin: Could not load the @t platform plugin "xcb"in问题,主要是安装pyt5后,缺少一些链接库,通过以下方法定位到缺少哪个链接库
。在环境中 export QT DEBUG PLUGINS=1
。执行出现该问题到程序,便可以定位到缺失的链接库。

在ubuntu系统中一般是libxcb-xinerama.so.0,通过sudo apt-get install libxcb-xinerama0

在centos系统中一般是ibxkbcommon-x11.so.0,通过yum install libxkbcommon-x11-devel
提供两个通过文件名查找包名到网站
http://rpm.pbone.net
http://rpmfind.net

参考:qt.qpa.plugin: Could not load the Qt platform plugin “xcb“ in问题_ustczhng2012的博客-CSDN博客

Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题_Linux_脚本之家 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值