You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KivyMD开发文本扫描App报错TypeError: 'module' object is not callable

问题排查与解决方案

错误原因

导入命名冲突导致报错:
你先从kivy.uix.image导入了Image控件类,后续又执行了from PIL import Image,后导入的PIL Image模块覆盖了前面的Kivy Image类。执行self.image = Image()时,实际是尝试调用PIL的Image模块,因此抛出TypeError: 'module' object is not callable错误。

修复方法

选其中一种即可:

  • 如果你后续不需要使用PIL的Image功能,直接删除from PIL import Image这行导入语句即可
  • 如果需要用到PIL的Image,将导入语句修改为别名形式避免冲突:
from PIL import Image as PILImage

修改完成后重新运行代码即可解决当前报错。

其他潜在兼容问题提示

  • 新版OpenCV中tostring()方法已废弃,可将buffer = cv2.flip(frame, 0).tostring()替换为buffer = cv2.flip(frame, 0).tobytes()避免运行警告
  • 如果修改后运行没有摄像头画面,可尝试将cv2.VideoCapture(1)改为cv2.VideoCapture(0),0为设备默认摄像头的索引

内容的提问来源于stack exchange,提问作者kamond

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 17:36:05