1 报错信息
error
如下:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in ".../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.
2 错误原因
opencv-python
与 pyqt
的 GUI
库产生冲突
3 解决方法
当使用除
OpenCV
之外的软件包创建GUI
时,应该选择安装opencv-python-headless
或者opencv-contrib-python-headless
(但是这样就无法使用cv2.imshow()
等方法了)
两个包的区别:
opencv-python
: Main modules packageopencv-contrib-python
: Full package (contains both main modules and contrib/extra modules)
headless
即不依赖 GUI
库。
- 卸载当前的
opencv-python
pip uninstall opencv-python
- 重新安装无
GUI
库的opencv-python
pip install opencv-python-headless