【问题标题】:Tesseract SyntaxError:'Creating User Config File' Error正方体语法错误:“创建用户配置文件”错误
【发布时间】:2018-03-19 17:28:02
【问题描述】:

我最近安装了 Tesseract 模块并找到了一些教程,但在互联网上没有任何我遇到的解决方案。以下是简单代码和错误:

from PIL import Image
from tesseract import image_to_string
a = Image.open('/Users/bob/Desktop/108.jpg')
b = image_to_string(a)
print(b)

这是错误:

print 'Creating user config file: {}'.format(_config_file_usr)
                                    ^
SyntaxError: invalid syntax

这是图片:108.png

【问题讨论】:

  • 尝试将from tesseract import image_to_string 更改为from .tesseract import image_to_string(带前导点)
  • 它没有用。现在它给出了以下错误:
  • Traceback(最近一次调用最后):文件“/Users/esat/Desktop/Noting/Program/Code/OCR.py”,第 2 行,在 from .tesseract import image_to_string ModuleNotFoundError:没有名为 'main.tesseract' 的模块; 'main' 不是包

标签: tesseract


【解决方案1】:

不要使用from tesseract import image_to_string

pip install pytesseractimport pytesseract

另外,请确保您在 .py 文件中分配 .exe,如下所示:

pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'

This answer goes into depth on how to do it correctly

您的程序将需要从以下方面进行修改:

a = Image.open('/Users/bob/Desktop/108.jpg')
b = image_to_string(a)`

text = pytesseract.image_to_string(Image.open('/Users/bob/Desktop/108.jpg'))

【讨论】:

    猜你喜欢
    • 2013-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 2019-12-28
    • 2018-04-08
    • 1970-01-01
    • 2013-02-06
    • 2019-06-22
    相关资源
    最近更新 更多