1

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.

7
  • I gues pytesseract isn't installed properly Commented Jul 3, 2018 at 12:37
  • How to install it "properly"? Uninstalling and installing doesn't help Commented Jul 3, 2018 at 12:52
  • 1
    can you run pip3 show pytesseract? and see if it is present. If it is present open a python shell and import pytesseract and see if you get error Commented Jul 3, 2018 at 13:11
  • Damn Buddy. You really helped me there. I tried to figure out why this shit didnt work for several hours. And the mistake was that I installed it with pip and not with pip3 using Python3. Now it works. Thank you very much Sir. Commented Jul 3, 2018 at 14:10
  • 1
    cool. Shall I add it as a solution? Commented Jul 3, 2018 at 14:11

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

pytesseract.pytesseract.tesseract_cmd=path/to/tesseract
3

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.

Comments

3

~ 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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.