2

I am trying to implement OCR in python. When I run the following code:

from PIL import Image
from pytesser import *

image_file = 'menu.jpg'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text

I get the following error:

Traceback (most recent call last):
 File "C:/Python27/ocr.py", line 2, in <module>
    from pytesser import *
  File "C:/Python27\pytesser.py", line 6, in <module>
ImportError: No module named Image

I have a folder name pytesser in my C:\Python27\Lib\site-packages directory and also one named PIL in the same directory which is from the installation of PILLOW.

Edit: I tried the solution at Why can't Python import Image from PIL?. But it doesn't seem to help

Community
  • 1
  • 1
Akhilesh Chobey
  • 317
  • 1
  • 3
  • 15
  • 1
    Possible duplicate of [Why can't Python import Image from PIL?](http://stackoverflow.com/questions/26505958/why-cant-python-import-image-from-pil) – Karin Aug 13 '16 at 05:10
  • Thanks. I tried the method mentioned there. However it doesn't help. I guess pytesser is having problem integrating with PIL. Not sure though. – Akhilesh Chobey Aug 13 '16 at 05:14

1 Answers1

1

As per the traceback, error is not from pytesser in c:\Python27\Lib\Site-Packages, it is coming from C:\Python27\pytesser.py line 6

Can you share the code at C:\Python27\pytesser.py line 6? or debug it by looking at code at C:\Python27\pytesser.py line 6

If you want your ocr.py to use pytesser at C:\Python27\Lib\site-packages (if it exists), please remove pytesser.py from the directory of ocr.py

If it is coded by you, ideally it should be from PIL import Image, not import Image

be_good_do_good
  • 4,311
  • 3
  • 28
  • 42