Python - Error when doing Image to Text using pytesseract

424 views Asked by At

My script:

from PIL import Image

print(pytesseract.image_to_string(Image.open('/Users/Sanya/Downloads/SimpleText.png')))

And then I got this error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 250, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanya/Documents/PythonFile/ImgToText.py", line 8, in <module>
    pytesseract.image_to_string(img, config=custom_config)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 370, in image_to_string
    return {
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 373, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 282, in run_and_get_output
    run_tesseract(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytesseract/pytesseract.py", line 254, in run_tesseract
    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.

when I tried the tesseract OCR trick, same error.

An answer would be greatly appreciate it.

0

There are 0 answers