0

I am using Pytesseract for the first time and am having an issue. I am assuming I am overlooking something basic, I am still learning python. I installed Tesseract-OCR on my computer and then used pip install for pytesseract. I also tried to pip install pillow but couldnt because it was already installed through pyautogui. I try to run the code below but get an error.

Question: What do I need to change or how can I correct this?

Traceback:

Traceback (most recent call last):
  File "C:\Users\bweibley\HC\test.py", line 20, in <module>
    text = get_text(img, region)
  File "C:\Users\bweibley\HC\test.py", line 8, in get_text
    return pytesseract.image_to_string(image.crop(region))
  File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 161, in image_to_string
    config=config)
  File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\bweibley\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Code:

#python 3.6
from PIL import Image
import pytesseract

# --- functions ---

def get_text(image, region):
    return pytesseract.image_to_string(image.crop(region))

def get_int(image, region):
    return int(get_text(image, region).replace(',', ''))

# --- main ---

# test on screenshots: 0.jpg ... 9.jpg
for x in range(10):
    img = Image.open('screenshots/{}.jpg'.format(x))

    region = (288, 664, 487, 706)
    text = get_text(img, region)
    print('Name:', text)

    region = (8666, 871, 1036, 920)
    value = get_int(img, region)
    print('Power:', value)

    region = (1292, 466, 1420, 515)
    value = get_int(img, region)
    print('Loot #1:', value)

    region = (1292, 555, 1420, 604)
    value = get_int(img, region)
    print('Loot #2:', value)

    region = (1292, 645, 1420, 694)
    value = get_int(img, region)
    print('Loot #3:', value)

    print('-----')
Brandon
  • 465
  • 3
  • 10
  • 19

1 Answers1

1

As for me Python can't find tesseract.exe.

You may have to find it manually and add its folder to PATH.

BTW: there is some comment about PATH inside file pytesseract.py

furas
  • 134,197
  • 12
  • 106
  • 148
  • I have found exactly what you are saying and even where to change it at, but do not fully understand what to change it to. Tesseract.exe is located in the C:\Program Files (x86)\Tesseract-OCR folder, but it does not look like it wants a folder destination in that variable as right now it is only 'tesseract' – Brandon Mar 17 '17 at 00:17