完整報錯如下:
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