macOS Big Sur
下载OpenCV后,运行代码cv.imshow()出现两个版本的冲突问题
# 在终端安装OpenCV
pip3 install opencv-python==4.4.0.40
# 在pycharm下运行代码
import cv2 as cv
img=cv.imread('./data/kitty.png',0)
cv.imshow('read_img',img)
k=cv.waitKey(0)
cv.destroyAllWindows()
报错如下:
objc[50066]: Class RunLoopModeTracker is implemented in both /Users/fariy/opt/anaconda3/envs/deeplearning/lib/python3.7/site-packages/cv2/.dylibs/QtCore (0x10773b7f0) and /Users/fariy/opt/anaconda3/envs/deeplearning/lib/libQt5Core.5.9.7.dylib (0x11f692a80). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7ff408625910) is not the object’s thread (0x7ff408471150).
Cannot move to target thread (0x7ff408625910)
查阅其他大佬提供的方法,大都使用本方法来解决此种问题。佬认为报错由于使用 conda 安装 pyqt ,用 pip 安装 opencv ,由版本冲突导致的。
# 卸载conda环境下的pyqt
conda uninstall pyqt
# 通过pip安装 PyQt
pip install PyQt5
pip install opencv-python
但是,用这种方法并没有解决我的问题,在conda环境下卸载pyqt一下午都没有完成。于是,我选择使用其他方法来解决。
已解决,解决方法为在终端下安装与OpenCV版本一致的opencv-python-headless:
pip3 install opencv-python-headless==4.4.0.40 -i https://pypi.douban.com/simple
成功!!!!