首页 > 解决方案 > PyQt5 和 OpenCV 有类似的库;如何避免两者之间的冲突?

问题描述

我在同一个 conda 虚拟环境中有 PyQt5 和 OpenCV。

opencv-python==3.4.1.15    
PyQt5==5.10.1    

每当我运行我的 PyQt5 应用程序时,我都会收到很多这样的警告:

objc[7992]: Class QCocoaPageLayoutDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0290) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f20). One of the two will be used. Which one is undefined.
objc[7992]: Class QCocoaPrintPanelDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0308) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport (0x10a387f70). One of the two will be used. Which one is undefined.    
objc[7992]: Class QCocoaApplicationDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0010) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed480). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSApplication is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109adffc0) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed4d0). One of the two will be used. Which one is undefined.    
objc[7992]: Class QCocoaMenuLoader is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109adff70) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed570). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSImageView is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0330) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed660). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSStatusItem is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0380) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed6b0). One of the two will be used. Which one is undefined.    
objc[7992]: Class QNSOpenSavePanelDelegate is implemented in both /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/cv2/.dylibs/QtGui (0x109ae0150) and /Users/alexryan/miniconda3/envs/qacker/lib/python3.5/site-packages/PyQt5/Qt/plugins/platforms/libqcocoa.dylib (0x10c6ed750). One of the two will be used. Which one is undefined.

处理此问题的适当方法是什么?

标签: pythonopencvpyqt5conda

解决方案


我通过使用 GUI 卸载 opencv 并安装无头版本解决了这个问题:

pip 卸载 opencv-contrib-python

pip install opencv-contrib-python-headless

opencv 中的 namedWindow 函数仍然有效。


推荐阅读