7

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.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Charlie22
  • 71
  • 1
  • 4
  • 1
    Did you mean `/usr/local/bin/tesseract` instead of `usr/local/bin/tesseract`? – a spaghetto Jan 21 '18 at 23:39
  • @quartata I meant to put that. Sorry. – Charlie22 Jan 22 '18 at 19:07
  • So Sad, you did not get any help, from the last and only place we would expect to not fail us. – agent18 Apr 16 '18 at 20:17
  • These answers helped me, I have a similar issue. From the link you have given 1. [This](https://stackoverflow.com/a/35736752/5986651) and 2. [3rd point in this](https://stackoverflow.com/a/46420593/5986651). I solved my issue as explained [here](https://stackoverflow.com/questions/49829307/emacs-python-not-able-to-find-package-module/49866388#49866388) – agent18 Apr 16 '18 at 21:21

3 Answers3

8

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

Salman
  • 924
  • 1
  • 7
  • 20
1

For me below steps worked in Google Colab:

!pip install pytesseract

import pytesseract

!sudo apt install tesseract-ocr
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
-2

on mac: you firs install brew, copy and paste:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

after:

brew install tesseract -- all languages 

fonds:

LuFFy
  • 8,799
  • 10
  • 41
  • 59