1. 程式人生 > 實用技巧 >Mac下Python執行時報錯:Class QMacAutoReleasePoolTracker is implemented in both /.../site-packages/PyQt5/... and /.../site-packages/cv2/...

Mac下Python執行時報錯:Class QMacAutoReleasePoolTracker is implemented in both /.../site-packages/PyQt5/... and /.../site-packages/cv2/...

完整報錯如下:

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

這樣就可以正常執行opencv和PyQt5了。


參考文章:https://blog.csdn.net/qq_43444349/article/details/106602543