1
$\begingroup$
 ExternalEvaluate["Python", "

 import pytesseract
 from PIL import Image
 import os
 import numpy as np


 dir_source='/Users/hypergroups/test'     
 files=os.listdir(dir_source)
 for basename in files:
     if '.jpg' in basename:
         file_img=os.path.join(dir_source,basename)
         file_export=os.path.join(dir_source,basename+'.txt')
         print '__',file_img
         image=Image.open(file_img)
         img=image
         code= pytesseract.image_to_string(img)

 "]

I'm on mac with Mathematica 11.3.

I can run this code without error information in Pycharm with the same python interpreter. I installed tesseract by brew install tesseract and I can run tesseract in terminal.


Error in External Run

Traceback (most recent call last):
  File "/Applications/Mathematica.app/Contents/SystemFiles/Components/\
ExternalEvaluate_Python/Resources/wolframevaluate/evaluate.py", line \
123, in runEvalLoop
    exec(codeobj,globals())
  File "file", line 26, in <module>
  File "/Users/hypergroups/Program/anaconda2/lib/python2.7/site-\
packages/pytesseract/pytesseract.py", line 294, in image_to_string
    return run_and_get_output(*args)
  File "/Users/hypergroups/Program/anaconda2/lib/python2.7/site-\
packages/pytesseract/pytesseract.py", line 202, in run_and_get_output
    run_tesseract(**kwargs)
  File "/Users/hypergroups/Program/anaconda2/lib/python2.7/site-\
packages/pytesseract/pytesseract.py", line 172, in run_tesseract
    raise TesseractNotFoundError()
TesseractNotFoundError: tesseract is not installed or it's not in \
your path
$\endgroup$
  • $\begingroup$ Just to let you know, TextRecognize appears to use Tesseract internally. $\endgroup$ – Carl Lange Dec 27 '18 at 12:26
  • 1
    $\begingroup$ You could consider doing import pip and then pip.main(['install', 'tesseract']), as it seems like the problem is that the python Mathematica is using doesn't have the tesseract package installed. $\endgroup$ – Carl Lange Dec 27 '18 at 12:28
  • 1
    $\begingroup$ as the error messages are from the pytesseract package, I don't think that the problem is the python package. It rather seems that the tesseract executable can not be found. This is not unreasonable as the environment might be different when called from within Mathematica. This can either be fixed by checking and extending the path to have the tesseract executable available or by setting the tesseract_cmd variable (at least according to pypi.org/project/pytesseract). I would search that site for more information about the prerequisites for the package to work... $\endgroup$ – Albert Retey Dec 30 '18 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.