Search code examples
pythonpython-tesseract

I get error using tesseract package in python


I am trying to read the text in a cheque using pytesseract OCR. I have installed the required python packages required for this task e.g. pip install pytesseract.

However when I try to use the package to read the file I get the following error:

 pytesseract.image_to_string(im, lang='eng')
Traceback (most recent call last):

  File "<ipython-input-17-d7d9f430493b>", line 1, in <module>
    pytesseract.image_to_string(im, lang='eng')

  File "C:\Users\BRIGHT\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 294, in image_to_string
    return run_and_get_output(*args)

  File "C:\Users\BRIGHT\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 202, in run_and_get_output
    run_tesseract(**kwargs)

  File "C:\Users\BRIGHT\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 172, in run_tesseract
    raise TesseractNotFoundError()

TesseractNotFoundError: tesseract is not installed or it's not in your path

This error dosent make sense because I actually import the package without getting any error. But when I try to use it I get the error.

Here is my code:

from PIL import Image
import pytesseract

im=Image.open('BritishChequeAnnotated.jpg')
text=pytesseract.image_to_string(im, lang='eng')

Solution

  • The documentation for tesseract makes this clear.

    https://pypi.org/project/pytesseract/

    # If you don't have tesseract executable in your PATH, include the following:
    pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'