Python 报错 qt.qpa.plugin Could not load the Qt platform plugin xcb 解决方案

2024-05-24 09:53:17 浏览数 (1)

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

错误信息

1234

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

12

pip uninstall opencv-pythonpip install opencv-python-headless

解决了我的问题

参考资料

  • https://blog.csdn.net/HaoZiHuang/article/details/131262745
  • https://github.com/PaddlePaddle/PaddleOCR/issues/6798
  • https://github.com/NVlabs/instant-ngp/discussions/300

文章链接: https://cloud.tencent.com/developer/article/2420073

0 人点赞