1

I've read a couple other answers on this, but I'm still stuck. I imagine I'm doing something stupid, but this doesn't work:

import pytesseract
from PIL import Image

def tryTesseract(u):
    return(pytesseract.image_to_string(Image.open(u)))


loc = 'C:\\Python\\Lineups\\558.png'

print(pytesseract)
print(tryTesseract(loc))

The first line prints:

<module 'pytesseract' from 'C:\Python\lib\site-packages\pytesseract\init.py'>

But the second prints several lines of error and culminates in:

pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.

This seems weird if the first line works. I BELIEVE I have correctly added it to path though, and it is correctly installed, as in this screenshot:

CMD screenshot

Full error message:

Python error

Edited for exciting new error. I followed user3250052's advice and am now getting a new error (CMD window on top of Python window here:)

New error

from PIL import Image

def tryTesseract(u):
    return(pytesseract.image_to_string(Image.open(u)))


loc = os.path.join('C','Python','Lineups','558.png')
pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR'

print(pytesseract)
print(tryTesseract(loc))```

1 Answer 1

1

That is a file not fond error. Try

loc = os.path.join('C','Python','Lineups','558.png')

you might also need

pytesseract.tesseract_cmdloc = r'<full_path_to_your_tesseract_executable>'
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply. I tried adding that, but get the same error. Would the line 'print(pytesseract)' work if this was the problem?
your right it wouldn't. It looks like a file not found error by the way. use os.path()
Aha, the error is now different, it just says: FileNotFoundError: [Errno 2] No such file or directory: 'C\\Python\\Lineups\\558.png' Which is weird as I can see it in the directory. The rest of the error is gone though...
Is it possible that the file is opened in another program?
Thanks Dunski, it was indeed open in another program - or at least, a reboot fixed the problem. Guess I forgot the first rule of computer troubleshooting...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.