完整报错如下:
objc[22334]: Class QMacAutoReleasePoolTracker is implemented in both /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (0x10a5e30f8) and /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/QtCore (0x114ab7700). One of the two will be used. Which one is undefined.
objc[22334]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (0x10a5e3170) and /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/QtCore (0x114ab7778). One of the two will be used. Which one is undefined.
objc[22334]: Class KeyValueObserver is implemented in both /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (0x10a5e3198) and /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/QtCore (0x114ab77a0). One of the two will be used. Which one is undefined.
objc[22334]: Class RunLoopModeTracker is implemented in both /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyQt5/Qt/lib/QtCore.framework/Versions/5/QtCore (0x10a5e31e8) and /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/cv2/.dylibs/QtCore (0x114ab77f0). One of the two will be used. Which one is undefined.
报错原因:
mac版本下安装的opencv包包含一些qt的头文件与PyQt5冲突了,导致无法正确导入相应的包。
解决方案
- 删除原有的opencv(这里看到有些博客写的是使用命令:pip uninstall opencv-contrib-python,但实际上我的pycharm中是没有安装opencv-contrib-python的,我安装的是opencv-python,所以使用删除命令前,先要看看自己安装的是什么opencv)
pip uninstall opencv-python
- 安装opencv-headless版本:
pip install opencv-contrib-python-headless