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

Python运行Tesseract报错:NameError: name 'Output' is not defined

解决Pytesseract中NameError: name 'Output' is not defined的问题

这个错误的原因非常明确:你在调用pytesseract.image_to_string()时使用了Output.STRING来指定输出类型,但没有从pytesseract模块中导入Output枚举类,也没有使用它的完整模块限定名,导致Python找不到这个名字。

Output是pytesseract内置的一个枚举,用来规范输出类型的取值,你可以通过两种方式解决这个问题:

  • 方法一:显式导入Output
    修改你的导入语句,加上对Output的导入:

    import pytesseract
    from pytesseract import Output  # 新增这一行
    

    这样之后你就能正常使用Output.STRING了。

  • 方法二:使用完整的模块限定名
    如果你不想额外导入,直接把代码里的Output.STRING替换成pytesseract.Output.STRING即可:

    print(pytesseract.image_to_string(threshold_manual, lang='eng', config='-psm 11', nice=0, output_type=pytesseract.Output.STRING))
    

另外顺便提两个代码里的小细节:

  • 你导入了Image模块但没有实际使用,可以考虑删掉这个无用导入;
  • for i in range(1, 2)只会循环一次(i=1),如果是要批量处理目录里的图片,这个逻辑可能需要调整~

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:51:16