本文最后更新于:2024年5月24日 早上

使用 Opencv 过程中突然 qt 报错,本文记录解决方案。

错误信息

1
2
3
4
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/python3.11/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 (from /python3.11/site-packages/cv2/qt/plugins), xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.

解决方案

问题原理没有弄清楚其实,到现在我都不明白为啥报这个错误

方案一

参考:https://blog.csdn.net/HaoZiHuang/article/details/131262745

在环境变量中添加:

1
export DISPLAY=:0

可以防止代码报错,但是无法显示图片

方案二

参考:https://github.com/NVlabs/instant-ngp/discussions/300

卸载 opencv-python 改安装 opencv-python-headless

1
2
pip uninstall opencv-python
pip install opencv-python-headless

解决了我的问题

我安装的 opencv-python-headless 版本为 4.5.5.62

参考资料



文章链接:
https://www.zywvvd.com/notes/coding/python/python-opencv-qt-error/python-opencv-qt-error/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Python 报错 qt.qpa.plugin Could not load the Qt platform plugin xcb 解决方案
https://www.zywvvd.com/notes/coding/python/python-opencv-qt-error/python-opencv-qt-error/
作者
Yiwei Zhang
发布于
2024年5月23日
许可协议