Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tesseract SyntaxError:'Creating User Config File' Error

Tags:

tesseract

I have recently installed the Tesseract module and found some tutorials, but there was not any solution on the internet which I comfronted. Here are the simple codes and the error:

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)

Here is the error:

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

Here is the image: 108.png

like image 745
antisycop Avatar asked Mar 19 '18 17:03

antisycop


People also ask

Does Pytesseract need Tesseract?

Pytesseract or Python-tesseract is an OCR tool for python that also serves as a wrapper for the Tesseract-OCR Engine. It can read and recognize text in images and is commonly used in python ocr image to text use cases.

What is config in Tesseract?

Tesseract config files consist of lines with variable-value pairs (space separated). The variables are documented as flags in the source code like the following one in tesseractclass.


1 Answers

Don't use from tesseract import image_to_string

Do pip install pytesseract and import pytesseract

Also, make sure you're assigning the .exe in your .py file like so:

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

This answer goes into depth on how to do it correctly

and your program will need to be reworked from:

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'))
like image 194
Stephen Avatar answered Nov 02 '22 23:11

Stephen