0

Problem

My tesseract (tesserocr) is not found by the emacs python interpreter, but I am able to use tesseract on the terminal as well as in my Spyder installation. Emacs python interpreter is able to import pytesseract, but not find tesserocr. I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eghx/agent18/project-gym/tests/thresholding.py", line 34, in image_to_string2
    print(image_to_string(img_open))
  File "/home/eghx/anaconda3/lib/python3.6/site-packages/pytesseract-0.1.7-py3.6.egg/pytesseract/pytesseract.py", line 122, in image_to_string
  File "/home/eghx/anaconda3/lib/python3.6/site-packages/pytesseract-0.1.7-py3.6.egg/pytesseract/pytesseract.py", line 46, in run_tesseract
  File "/home/eghx/anaconda3/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/home/eghx/anaconda3/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'

when I run

pytesseract.image_to_string(img)

However I don't get this error when I open EMACS from a terminal instead of the desktop. It appears that the path variable is inherited differently in the desktop version and terminal version of emacs. ODD!

Explanation

I have anaconda installation here:/path/to/anaconda3

I have added this line to my init file to run this particular python installation

(setq python-shell-interpreter "/path/to/anaconda3/bin/python")

I installed both pytesseract and tesserocr using conda install

which tesseract gives:

/path/to/anaconda3/bin/tesseract

$ echo $PATH gives:

/path/to/anaconda3/bin:/usr/local/sbin:/usr/lo....

What I did

I copied the sys.path from the working Spyder IDE to emacs python interpreter and still didn't work.

I looked around and found this but the top answer does not pertain to my case, as my $PATH variable contains the necessary path.

Can someone guide me? I am a noob. I have emacs 27 and ubuntu 16 and conda 4.5.0.

1 Answer 1

0

This is a possible duplicate of OSError: [Errno 2] No such file or directory using pytesser

Answer was found as per the 3rd point in the link, quoted below:

import pytesseract

pytesseract.pytesseract.tesseract_cmd = 'path-to-tesseract-including-bin'

In my case,

import pytesseract
pytesseract.pytesseract.tesseract_cmd = '/home/anaconda3/bin/tesseract'

This is only a temporary hack to get image_to_string to work, by typing the above in every file.

Why the $PATH variable having the /home/anaconda3/bin is not enough to get it to work sufficiently is not known. This seems to be a slighty long-term-temporary solution.

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

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.