2

I need OCR for a certain project, after searching online I decided to use python and tesseract. Right now I am trying to run the following code just to see if it works:

import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
print(pytesseract.image_to_string(Image.open("C:\Documents and Settings\Yerutnik\Desktop\file.bmp")))

However, I am getting the following error:

Traceback (most recent call last):
  File "C:\Documents and Settings\Yerutnik\Desktop\test1.py", line 2, in <module>
    import pytesseract
  File "C:\Python27\lib\site-packages\pytesseract\__init__.py", line 2, in <module>
    from .pytesseract import ALTONotSupported
  File "C:\Python27\lib\site-packages\pytesseract\pytesseract.py", line 89
    f"{tesseract_cmd} is not installed or it's not in your PATH."
                                                                ^
SyntaxError: invalid syntax

I am running this on a Windows XP 32bit machine (must use this machine), Python 2.7.9, Tesseract 4.0.0 (tested working separately in cmd, and I checked that it is in PATH).

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Yerutnik
  • 21
  • 1
  • Why don't you use Python 3? Python 2 is outdated. That would fix this problem. – mkrieger1 Apr 07 '21 at 08:32
  • Does this answer your question? [Getting an "invalid syntax" when trying to perform string interpolation](https://stackoverflow.com/questions/42126794/getting-an-invalid-syntax-when-trying-to-perform-string-interpolation) – mkrieger1 Apr 07 '21 at 08:33

2 Answers2

0

you use pytesseract for python3 (f-string is python3 feature) in python2.7 Try some old version of pytesseract.

user898678
  • 2,994
  • 2
  • 18
  • 17
  • we tried to use older versions of pytesseract(0.1, 0.1.5 , 0.2.5 , 0.2.2 , 0.2.0) and all of them return me the same error when trying to use pip install: 'ERROR: Could not find a version that satisfies the requirement pytesseract-0.1 ( from versions: none) ERROR: No matching distribution found for pytesseract-0.1' – Yerutnik Apr 06 '21 at 19:32
0

I was able to fix this by downgrading pytesseract (as suggested by user898678) from 4.0.0 to 0.2.2, upgrading pip from 1.5.2 to 20, and installing pytesseract from web instead of using a wheel file.

Yerutnik
  • 21
  • 1