【Bug】AttributeError: module ‘cv2‘ has no attribute ‘imread‘
今天记录一下很伤悲(SB)的bug:
AttributeError: module ‘cv2’ has no attribute ‘imread’
准备学习一下opencv-python中的resize()函数,然后新建了一个.py脚本
import cv2img = cv2.imread("audi.jpg")
# 后面还有很多代码,不输入了
运行代码,
AttributeError: module ‘cv2’ has no attribute ‘imread’
此时我一脸懵逼,难道环境崩了?opencv挂了,语法没毛病啊。。。真的是一脸问号。。。
然后,我就把3.4的opencv升级到了4.5,发现还是不行!!!
然后开启了搜索之路,在某乎上看到一个话题,然后点进去看到网友的回复。。。。我当时真的很无语。。
哈哈哈,犯了一个很伤悲(SB)的错误。。。
回忆以前好像犯过类似的错误,,,就这样吧。。。
-----------------------------2022.10.17更新---------------------------------
看到评论,原来大家都踩过坑。。。
今天解释一下,为什么不能将脚本命名为cv2.py
因为你的代码开头是:
import cv2
它导入的是当前你命名脚本,而不是安装的opencv-python的cv2。。。
所以脚本命名要注意,就跟关键字不能当变量一样。
参考:
https://www.zhihu.com/question/298820008
【Bug】AttributeError: module ‘cv2‘ has no attribute ‘imread‘相关推荐
- 【Bug】AttributeError: module ‘gast‘ has no attribute ‘Index‘
pe self._apply(transformer, node_wrapper, log_level=index + 1) File "/home/ubuntu/anaconda3/env ...
- 【BUG】AttributeError: module ‘gast‘ has no attribute ‘Index’
1.问题:AttributeError: module 'gast' has no attribute 'Index' 2.解决方法: 原因:gast版本过高 pip install gast==0. ...
- 【Python】AttributeError: module ‘numpy’ has no attribute ‘unit8’ 的解决方法
经排查,下面的一行代码出了异常: mask2 = np.where((mask1 == 2) | (mask1 == 0), 0, 1).astype('unit8') 异常类型是: Attribut ...
- 【解决问题】AttributeError: module ‘pandas‘ has no attribute ‘ewma‘报错解决方法
将 ewma60=pd.ewma(aapl_px,span=60) 改为 ewma60 = pd.DataFrame.ewm(aapl_px,span=60).mean()
- AttributeError: module 'cv2' has no attribute 'imread'
主要原因是程序命名为cv.py或者cv2.py,只需将改为其他的就可以了
- 解决: AttributeError: module 'cv2' has no attribute 'SURF'
AttributeError: module 'cv2' has no attribute 'SURF' 遇到该问题时,网友多是建议补个包,即pip install opencv-contrib-py ...
- Python3 AttributeError: module 'cv2' has no attribute 'SIFT'
参考 https://blog.csdn.net/yuxuan_08/article/details/87966840 在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会 ...
- AttributeError: module ‘cv2‘ has no attribute ‘SIFT‘
问题:在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会产生错误:AttributeError: module 'cv2' has no attribute 'SIFT' ...
- 解决AttributeError: module ‘cv2‘ has no attribute ‘CV_HAAR_SCALE_IMAGE‘
解决AttributeError: module 'cv2' has no attribute 'CV_HAAR_SCALE_IMAGE' 问题描述: 代码: frontalFaces = faceC ...
最新文章
- B站项目资源过于敏感,2h后删,抓紧保存!!!
- Ubuntu里的vi编辑器不好用的解决办法
- 安装firefox 3.6.4 (ubuntu 10.04)
- ASP.NET专题研究——角色和Profile
- 比尔盖茨,马斯克、霍金都告诉你:为什么要警惕人工智能(中)
- iOS: bundle name, bundle display name, bundle identifier...
- linux 命令修改网络,linux网络命令学习
- shuffle理解【增加模型的泛化能力】
- java上机实验答案_java上机实验答案与解析
- 飞书正式发布5.0版 推出飞书人事、合同、审批等多款新产品
- Treap 树堆 容易实现的平衡树
- 图片处理--连环画特效
- JSP概述--JSP的起源,本质,运行原理
- php处理har,harviewer har解析工具
- 全新UI四方聚合支付系统源码/新增USDT提现/最新更新安全升级修复XSS漏洞补单漏洞
- 安卓开发之路----转自任玉刚大神
- SEO中的关键词密度该如何布局
- [转载]document.readyState
- Valentino Beauty华伦天奴美妆即将登陆中国市场
- 在VMware 14虚拟机下,ndn-cxx和NFD平台搭建