Pytesseract TesseractNotFoundError [Python 3]

I am getting an Error using pytesseract. I installed it via pip install.

Code:

import pytesseract
from PIL import Image

img = Image.open('frame_0000.png')

x = pytesseract.image_to_string(Image.open('frame_0000.png'))

The Error occurs in the last line. (x = ...)

Result:

Traceback (most recent call last): File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_and_get_output run_tesseract(**kwargs) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 165, in run_tesseract proc = subprocess.Popen(command, **subprocess_args()) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in init restore_signals, start_new_session) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child startupinfo) FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Artur\Desktop\Pytesseract_test.py", line 6, in x = pytesseract.image_to_string(Image.open('frame_0000.png')) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 286, in image_to_string return run_and_get_output(image, 'txt', lang, config, nice) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 201, in run_and_get_output raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

I am trying to get a workaround running but my inexperience prevents me from implementing this correctly:

tessdata_dir_config = '--tessdata-dir "<replace_with_your_tessdata_dir_path>"'
# Example config: '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
# It's important to include double quotes around the dir path.

pytesseract.image_to_string(image, lang='chi_sim', config=tessdata_dir_config)

Can somebody please help me solve this? I don't get the solutions provided online to work.

Upvotes: 1

Views: 16267

Answers (3)

Stanley
Stanley

Reputation: 2794

For anyone else with this problem

I had to go into the pytesseract.py file and changed my:
tesseract_cmd = 'tesseract'
To:
tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'

Disclaimer: doing
pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
did not fix the problem

Upvotes: 5

Louis Lin
Louis Lin

Reputation: 211

~ For anyone else who still comes across this and is a beginner programmer( as I consider myself one)

For Mac OS

Try finding where the tesseract.exe is- if you installed it using brew, on your the terminal use:

>brew list tesseract

This should list where your tesseract.exe is, somewhere more or less like

> /usr/local/Cellar/tesseract/3.05.02/bin/tesseract

Then following their instructions:

pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'

should do the trick!

Upvotes: 3

Mufeed
Mufeed

Reputation: 3208

The error occurred because the code is compiled using python3 but the module was installed using pip.
So the pytesseract module was installed to Python2 instead of Python3.
Installing using pip3 would solve the problem.

Upvotes: 3

Related Questions