2

I am getting the following error:

ModuleNotFoundError: No module named 'Image'

while running the below script for OCR:

import Image
from tesseract import image_to_string


print(image_to_string(Image.open('marlboro.png'), lang='eng'))

I am using Spider through Anaconda and have Pillow installed.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • When I had this issue, I re-installed pytesseract and it worked. Sometimes it's as easy as that. – Benji Jul 13 '20 at 13:24

2 Answers2

5

Have a look at the docs, where you can see some basic examples. In short: You need to specify that you are importing Image from PIL:

from PIL import Image
FlyingTeller
  • 17,638
  • 3
  • 38
  • 53
  • 1
    Thanks i chagnged this to, which removed the previous error but a new one popped up - from PIL import Image from pytesseract import image_to_string print(image_to_string(Image.open('marlboro.png'))) But i am getting a new error now - – Shauvik Choudhury Mar 06 '18 at 10:18
0

You should install pytesseract use pip (also see guide):

pip install pytesseract

and then:

from PIL import Image
from pytesseract import image_to_string

print(image_to_string(Image.open('marlboro.png'), lang='eng'))

or use python cross-platform module tesseract:

pip install tesseract

and use it as you have in your question:

from PIL import Image
from tesseract import image_to_string

print(image_to_string(Image.open('marlboro.png'), lang='eng'))
godot
  • 3,422
  • 6
  • 25
  • 42