6

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

3
  • Try changing from tesseract import image_to_string to from .tesseract import image_to_string (with leading dot) Commented Mar 20, 2018 at 7:50
  • 1
    It did not work. Now it's giving this following error: Commented Mar 20, 2018 at 13:54
  • Traceback (most recent call last): File "/Users/esat/Desktop/Noting/Program/Code/OCR.py", line 2, in <module> from .tesseract import image_to_string ModuleNotFoundError: No module named 'main.tesseract'; 'main' is not a package Commented Mar 20, 2018 at 13:54

1 Answer 1

7

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'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.