PyQt5和OpenCV有类似的库; 如何避免两者之间的冲突?

16

我在同一个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.

应该如何妥善处理这个问题?


我在使用PyQt和OpenCV的Mac上遇到了类似的问题。你找到解决方案了吗? - Punit Soni
很遗憾,没有。 - Alex Ryan
你们找到解决方案了吗?@PunitSoni - sonja
@sona 不是的。这个问题也发布到了QtForum,但是目前该论坛似乎无法访问:https://forum.qt.io/topic/93012/how-do-i-specify-which-of-2-versions-of-the-qt-libs-should-be-used - Alex Ryan
我也遇到了同样的问题。你们找到解决方案了吗? - Ajinkya
2个回答

14

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

pip uninstall opencv-contrib-python

pip install opencv-contrib-python-headless

OpenCV中的namedWindow函数仍然可以使用。


我刚刚复制了这个并测试了你建议的内容,它起作用了,所以我给它一个赞。 - Rudder
我搜索了很多关于这个问题的内容,许多答案都太复杂了。这个答案简单易懂且有效。 - Holsety
问题也被我解决了。非常感谢你! - Tom

1
在我的情况下,我解决了这个问题,删除了opencv-python。
pip3 uninstall opencv-python

然后安装 opencv-headless

pip3 install opencv-python-headless

之后,我的应用程序再次运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接