今天记录一下很伤悲(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‘相关推荐

  1. 【Bug】AttributeError: module ‘gast‘ has no attribute ‘Index‘

    pe self._apply(transformer, node_wrapper, log_level=index + 1) File "/home/ubuntu/anaconda3/env ...

  2. 【BUG】AttributeError: module ‘gast‘ has no attribute ‘Index’

    1.问题:AttributeError: module 'gast' has no attribute 'Index' 2.解决方法: 原因:gast版本过高 pip install gast==0. ...

  3. 【Python】AttributeError: module ‘numpy’ has no attribute ‘unit8’ 的解决方法

    经排查,下面的一行代码出了异常: mask2 = np.where((mask1 == 2) | (mask1 == 0), 0, 1).astype('unit8') 异常类型是: Attribut ...

  4. 【解决问题】AttributeError: module ‘pandas‘ has no attribute ‘ewma‘报错解决方法

    将 ewma60=pd.ewma(aapl_px,span=60) 改为 ewma60 = pd.DataFrame.ewm(aapl_px,span=60).mean()

  5. AttributeError: module 'cv2' has no attribute 'imread'

    主要原因是程序命名为cv.py或者cv2.py,只需将改为其他的就可以了

  6. 解决: AttributeError: module 'cv2' has no attribute 'SURF'

    AttributeError: module 'cv2' has no attribute 'SURF' 遇到该问题时,网友多是建议补个包,即pip install opencv-contrib-py ...

  7. Python3 AttributeError: module 'cv2' has no attribute 'SIFT'

    参考 https://blog.csdn.net/yuxuan_08/article/details/87966840 在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会 ...

  8. AttributeError: module ‘cv2‘ has no attribute ‘SIFT‘

    问题:在用python3使用sift = cv2.SIFT()进行SIFT时候,可能会产生错误:AttributeError: module 'cv2' has no attribute 'SIFT' ...

  9. 解决AttributeError: module ‘cv2‘ has no attribute ‘CV_HAAR_SCALE_IMAGE‘

    解决AttributeError: module 'cv2' has no attribute 'CV_HAAR_SCALE_IMAGE' 问题描述: 代码: frontalFaces = faceC ...

最新文章

  1. B站项目资源过于敏感,2h后删,抓紧保存!!!
  2. Ubuntu里的vi编辑器不好用的解决办法
  3. 安装firefox 3.6.4 (ubuntu 10.04)
  4. ASP.NET专题研究——角色和Profile
  5. 比尔盖茨,马斯克、霍金都告诉你:为什么要警惕人工智能(中)
  6. iOS: bundle name, bundle display name, bundle identifier...
  7. linux 命令修改网络,linux网络命令学习
  8. shuffle理解【增加模型的泛化能力】
  9. java上机实验答案_java上机实验答案与解析
  10. 飞书正式发布5.0版 推出飞书人事、合同、审批等多款新产品
  11. Treap 树堆 容易实现的平衡树
  12. 图片处理--连环画特效
  13. JSP概述--JSP的起源,本质,运行原理
  14. php处理har,harviewer har解析工具
  15. 全新UI四方聚合支付系统源码/新增USDT提现/最新更新安全升级修复XSS漏洞补单漏洞
  16. 安卓开发之路----转自任玉刚大神
  17. SEO中的关键词密度该如何布局
  18. [转载]document.readyState
  19. Valentino Beauty华伦天奴美妆即将登陆中国市场
  20. 在VMware 14虚拟机下,ndn-cxx和NFD平台搭建

热门文章

  1. MySQL(InnoDB剖析):29---全文检索(倒排索引、全文索引/全文检索)
  2. Python爬虫||Xpath-以豆瓣电视剧为例
  3. buildroot技巧
  4. java正则表达式匹配字符串_java正则表达式如何匹配字符串
  5. 删除的备忘录内容怎么恢复?
  6. 免费软件真的免费吗?
  7. ai前世识别_AI人脸识别前世今生app下载
  8. Invalid bound statement (not found)错误解决办法
  9. 02Python基础知识
  10. 背景图片全屏拉伸显示