FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

Question:

i have installed the tasseract using

pip install pytesseract

whenever i tried to run this piece of code

from PIL import Image
import pytesseract
im = Image.open('hasan1.jpg')
print (pytesseract.image_to_string(im))

I got these errors.

 Traceback (most recent call last):
 File "ocr.py", line 34, in <module>
 text = pytesseract.image_to_string(Image.open(filename))
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 193, in image_to_string
 return run_and_get_output(image, 'txt', lang, config, nice)
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 140, in run_and_get_output
 run_tesseract(**kwargs)
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 111, in run_tesseract
 proc = subprocess.Popen(command, stderr=subprocess.PIPE)
 File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
 restore_signals, start_new_session)
 File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
 raise child_exception_type(errno_num, err_msg)
 FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
Asked By: HASAN LATIF

||

Answers:

I believe PyTesseract requires you to have the tesseract library installed on your system – PyTesseract is trying to run the command-line interface but it can’t find it presumably because you have only installed the python bindings.

If you are on an Ubuntu/Debian-based system, you can try:

sudo apt-get install tesseract-ocr

You can check the Tesseract installation docs for more info: https://tesseract-ocr.github.io/tessdoc/Home.html

Answered By: mxbi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.