I installed the pytesseract library using
pip install pytesseract
When I tried to use the image_to_text method, it gave me
FileNotFoundError: [WinError 2] The system cannot find the specified file
I looked for it and found that I had to change something in the pytesseract.py file and line
tesseract_cmd = 'tesseract'
should become
tesseract_cmd = path_to_folder_that_contains_tesseractEXE + 'tesseract'
I searched and found no tesseract.exe files in my Python folder, then reinstalled the library, but there was still no file. In the end, I replaced the line:
tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + 'pytesseract'
and my program threw:
pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')
What can I do to make my program work?
PS Here is my program code:
from pytesseract import image_to_string from PIL import Image, ImageEnhance, ImageFilter im = Image.open(r'C:\Users\\Desktop\ImageToText_Python\NoName.png') print(im) txt = image_to_string(im) print(txt)
Full check of the first attempt:
File "C:/Users/user/Desktop/ImageToText.py", line 10, in <module> text = pytesseract.image_to_string(im) File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string config=config) File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract proc = subprocess.Popen(command, stderr=subprocess.PIPE) File "C:\Python\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "C:\Python\lib\subprocess.py", line 1224, in _execute_child startupinfo) FileNotFoundError: [WinError 2]The system can not find the file specified
Full trace of the second attempt
Traceback (most recent call last): File "C:\Users\user\Desktop\ImageToText.py", line 6, in <module> txt = image_to_string(im) File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 125, in image_to_string raise TesseractError(status, errors) pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')