AttributeError: module 'cv2' has no attribute 'imread'问题以及安装opencv-python加了--user还是拒绝访问的解决办法

问题描述

最近用到了cv2模块,用eclipse运行,里面有条语句img=cv2.imread(‘images/1.png’),运行的时候突然报错,AttributeError: module ‘cv2’ has no attribute ‘imread’,然后就去百度,有博主说是“由于版权问题,这个算法被申请了专利,把版本降下去就可以了”,要求去降版本,我就去尝试pip install opencv-python==3.4.2.16,但是这时候又出现了一个错误,错误如下:

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'e:\\anaconda3\\Lib\\site-packages\\cv2\\cv2.cp36-win_amd64.pyd'
Consider using the `--user` option or check the permissions.

我按要求加了–user,又报错,错误如下:

ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'e:\\anaconda3\\lib\\site-packages\\cv2\\cv2.cp36-win_amd64.pyd'
Check the permissions.

解决方法

1.安装opencv-python、opencv-contrib-python出现拒绝服务,加了–user还是出现拒绝服务的原因是我的eclipse没关。关掉之后再进行安装即可解决!!!如果你使用的其他编译器都有可能干扰正常去安装包!!

2.AttributeError: module ‘cv2’ has no attribute 'imread’问题,我经过实践发现是我没有装opencv-contrib-python
输入下面命令即可

pip install opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple

填坑不易,且行且珍惜 如果帮助到你 评论一下 让更多人看到,解决大家的问题

发布了44 篇原创文章 · 获赞 97 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44573410/article/details/104453800