Tesseract 语法错误:'创建用户配置文件' 错误。

6

我最近安装了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(带有点号的前导) - Dmitrii Z.
1
它没有起作用。现在它显示以下错误: - antisycop
追溯(Traceback)最近的一次调用: 文件“/Users/esat/Desktop/Noting/Program/Code/OCR.py”,第2行,在<module>中 from .tesseract import image_to_string 模块未找到错误:没有名为'main.tesseract'的模块; 'main'不是一个包。 - antisycop
1个回答

6

不要使用from tesseract import image_to_string

而是要pip install pytesseract并且import pytesseract

此外,请确保在你的.py文件中像这样分配.exe:

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

这个答案深入探讨了如何正确地实现它

你的程序需要重新设计:

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

to

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接