Aouey
Aouey

Reputation: 11

Keep getting "AttributeError: Read" from pytesseract

I'm trying to take a screen grab with PILLOW and reading text from it using pytesseract but I keep seeing a "AttributeError: read". I've tried to read the documentation and google but haven't found anything.

from PIL import ImageGrab
from PIL import Image
import PIL

snapShot = PIL.ImageGrab.grab(0, 0, 500, 500)      #takes screenshot and stores it temporarily


pyt.pytesseract.tesseract_cmd = r'C:\Users\user\Desktop\project\venv\Scripts\pytesseract.exe'      #locate pytesseract exe

im = Image.open(snapShot)
text = pyt.image_to_string(im)

print(text)

Error code:

  File "C:\Users\user\Desktop\project\venv\lib\site-packages\PIL\Image.py", line 519, in __getattr__
    raise AttributeError(name)
AttributeError: read

Upvotes: 0

Views: 496

Answers (1)

Aouey
Aouey

Reputation: 11

As a comment pointed out the use of 'Image.open()' on a Image object causes the error. Removing this gave another error however 'PermissionError: [WinError 5] Access is denied' which was resolved by installing the tesseract client on top of the pytesseract package and pointing to it.

from PIL import ImageGrab
import PIL

snapShot = PIL.ImageGrab.grab(0, 0, 500, 500)      #takes screenshot and stores it temporarily


pyt.pytesseract.tesseract_cmd = r'C:\Program Files (x86)\Tesseract-OCR\tesseract\tesseract.exe'      #default path to tesseract client executable

text = pyt.image_to_string(snapshot)

print(text)

Upvotes: 1

Related Questions