Tesseract SyntaxError:“正在创建用户配置文件”错误

ant*_*cop 5 tesseract

我最近安装了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)
Run Code Online (Sandbox Code Playgroud)

这是错误:

print 'Creating user config file: {}'.format(_config_file_usr)
                                    ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

这是图像:108.png

Ste*_*hen 6

不要使用 from tesseract import image_to_string

pip install pytesseractimport 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)`
Run Code Online (Sandbox Code Playgroud)

text = pytesseract.image_to_string(Image.open('/Users/bob/Desktop/108.jpg'))
Run Code Online (Sandbox Code Playgroud)