0

I have a scenario where I have to fetch some text from an image. But I am getting the following errors when trying to do so:

runfile('/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py', 
wdir='/Users/vivekchowdary/Documents/untitled folder')
Traceback (most recent call last):

File "<ipython-input-3-95284fad16df>", line 1, in <module>
runfile('/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py', 
wdir='/Users/vivekchowdary/Documents/untitled folder')

File "/anaconda3/lib/python3.7/site- 
packages/spyder_kernels/customize/spydercustomize.py", line 704, in 
runfile
execfile(filename, namespace)

File "/anaconda3/lib/python3.7/site- 
packages/spyder_kernels/customize/spydercustomize.py", line 108, in 
execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py", line 3, in <module>
from pytesseract import *

File "/Users/vivekchowdary/Documents/untitled 
folder/pytesseract.py", line 6, in <module>
text = image_to_string(image_file)

NameError: name 'image_to_string' is not defined

I have used the following code:

`from PIL import Image
from matplotlib import pyplot as plt
from pytesseract import *
image_file='/Users/vivekchowdary/Documents/untitled 
folder/Scan0013.jpg'
im=Image.open(image_file)
text = image_to_string(image_file)
print ("=====output=======\n")
print (text)`

My expected result is, it must fetch all the text from the 'jpg' image and print it on the screen.

Vivek
  • 336
  • 2
  • 4
  • 18
  • I think this problem should be solved if you rename the file you're trying to run, i.e. `/Users/vivekchowdary/Documents/untitled folder/pytesseract.py` to something other than `pytesseract.py`. That's because `pytesseract` is the name of the module you're trying to use, so you can't name your files with the same name or you'll make Python to mistakenly assume that your file is the module itself. – Carlos Cordoba Apr 11 '19 at 09:13
  • @CarlosCordoba you were right. I tried changing the name of the file and I didn't get the previous error. But this time it says "TesseractNotFoundError: tesseract is not installed or it's not in your path". The problem here is I already installed tesseract. Can you please help me in setting its path? – Vivek Apr 11 '19 at 17:24

0 Answers0