1

I have this code:

try:   
    from PIL import Image as Img
    import os
    import pytesseract as tss
except ImportError as error:
    raise Exception(str(e))

from passporteye import read_mrz
#So far you're using windows always do this; esp. if you've haven't add teseract.exe to PATH
#tesseract_cmd=r'C:\Program Files (x86)\Tesseract-OCR'

def Get_mrz(image_file):
    print("This will take a while.")
    try:
        mrz=read_mrz(image_file,save_roi=True)
        print("Done")
    except Exception as e:
        raise Exception("THERE WAS AN EXCEPTION "+str(e))
    
    if mrz!=None:
        print(mrz)
    else:
        return "Cannot read text"
def Credits():
    print("This is work...")

#The test is below
Get_mrz("img/id_card2f.jpg")
Credits()

It keeps giving this error:

Traceback (most recent call last):
  File "main_stuff.py", line 28, in <module>
    Get_mrz("img/id_card2f.jpg")
  File "main_stuff.py", line 18, in Get_mrz
    raise Exception("THERE WAS AN EXCEPTION "+str(e))
Exception: THERE WAS AN EXCEPTION tesseract is not installed or it's not in your PATH. See README file for more information.

but I dont know why.Tesseract-ocr binary was succesfully installed and added to my PATH. I know this because if I run tesseract --version in any directory it gives

tesseract v5.0.0-alpha.20200328
 leptonica-1.78.0
  libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
 Found AVX2
 Found AVX
 Found FMA
 Found SSE
 Found libarchive 3.3.2 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5
 Found libcurl/7.59.0 OpenSSL/1.0.2o (WinSSL) zlib/1.2.11 WinIDN libssh2/1.7.0 nghttp2/1.31.0
5
  • Did you install the PyPi package? pypi.org/project/pytesseract Commented Aug 15, 2020 at 9:14
  • Just checking but.. Is there any chance when you run tesseract --version you are already in this directory C:\Program Files (x86)\Tesseract-OCR\ ? Commented Aug 15, 2020 at 9:23
  • @user3250052 no.I said 'any directory' Commented Aug 15, 2020 at 9:33
  • oh yeah. sorry. does it work if you pass the path explicitly like this tss.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>' Commented Aug 15, 2020 at 9:50
  • @user3250052 Yes.I had gotten it 2 mins b4 u sent ur answer.Do u want to answer it so Ill upvote and accept ur answer? Commented Aug 15, 2020 at 10:01

1 Answer 1

1

pass the path explicitly like this

tss.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.