Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No such file or directory: 'tesseract': 'tesseract' even though where to find tesseract is specified in pytesseract.py

So I have been working on this problem for awhile and while others have had questions similar to this but nothing has worked for me:

I am trying to use pytesseract for a project and I have it installed under User/Environments/testEnv/lib/python3.6/site-packages/pytesseract/

I have tesseract installed under usr/local/bin

I have gone into Users/User/Environments/testEnv/lib/python3.6/site-packages/pytesseract/pytesseract.py and changed tesseract_cmd = 'tesseract' to tesseract_cmd = '/usr/local/bin/tesseract' as suggested here: OSError: [Errno 2] No such file or directory using pytesser

This did not work. I tried to run this:

try:
    import Image
except ImportError:
    from PIL import Image
import pytesseract

img = Image.open('screenshot.png')
img.load()
i = pytesseract.image_to_string(img)
print (i)

and I get this:

Traceback (most recent call last):
  File "/Users/User/Environments/testEnv/testTess.py", line 26, in <module>
    i = pytesseract.image_to_string(img)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 122, in image_to_string
    config=config)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytesseract/pytesseract.py", line 46, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract': 'tesseract'

This is telling me that tesseract can't be found even though I specified in pytesseract.py. This befuddles me.

Note: You can probably tell but I am using a virtualenv - could this be an issue due to the fact that tesseract is not in the environment but pytesseract is?

I am using mac osx and python3.6.

I am new to coding and I simply cannot find a solution to this issue.

Thanks!

UPDATE: I have now re-downloaded tesseract and tried this again and also tried putting tesseract here: /Users/User/Environments/testEnv/bin/tesseract/3.05.01/bin/tesseract so that is is within the environment in case that was an issue.

I still cannot make anything work! Absolutely any suggestions would help.

FINAL UPDATE: I gave up on the environment and deleted it and program worked.

like image 790
Charlie22 Avatar asked Jan 21 '18 23:01

Charlie22


People also ask

Does Pytesseract need Tesseract installed?

You can confirm that pytesseract is installed in your virtual environment by hopping into the Python REPL and trying to import it. pytesseract is installed. Great! But before we can use it, we need to install the tesseract application.

How do I know if Tesseract is installed?

To verify if Tesseract is successfully installed, you can hit your terminal and type the following. If you receive a few lines of prompt similar to the one below, your Tesseract is installed correctly. Otherwise, you might want to check what has gone wrong by starting from your PATH variable in your system.

How do I find the Tesseract path in Linux?

To install Tesseract on Debian or Ubuntu Linux distribution, use apt as shown in the screenshot below. This will install Tesseract under /usr/share/tesseract-ocr/4.00/tessdata. Note: For other Linux distributions, jump to Install Tesseract from Sources. By default, Tesseract will install the English language pack.


2 Answers

You should firstly install tesseract-ocr like this:

on Linux: sudo apt-get install tesseract-ocr

on mac: brew install tesseract

For more information, see: this link

like image 136
Salman Avatar answered Oct 19 '22 08:10

Salman


For me below steps worked in Google Colab:

!pip install pytesseract

import pytesseract

!sudo apt install tesseract-ocr
like image 42
Rupak Goyal Avatar answered Oct 19 '22 09:10

Rupak Goyal