pyqt与opencv-python冲突解决(Could not load the Qt platform plugin “xcb“ )
Could not load the Qt platform plugin "xcb"
·
问题描述
QObject::moveToThread: Current thread (0x2ba89440) is not the object's thread (0x2c3d7f30).
Cannot move to target thread (0x2ba89440)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/i/anaconda3/envs/img/lib/python3.8/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, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.
已中止 (核心已转储)
python低版本(<=3.8)解决方式
pip install opencv-python==4.1.2.30
4.2版本以下的opencv-python没有cv2/qt/plugins,所以不存在冲突
python高版本解决方式
在代码中加入
import os
os.environ.update({"QT_QPA_PLATFORM_PLUGIN_PATH": "/xxx/.local/lib/python3.11/site-packages/cv2/qt/plugins/platforms"})
让python代码找到cv2/qt/plugins就行
摆烂方式
pip install opencv-python-headless
不涉及opencv的显示功能就不需要这么多功能,也不会冲突
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)