【问题标题】:python - tesseract is not installed or it's not in your PATH. See README file for more informationpython - tesseract 未安装或不在您的 PATH 中。有关更多信息,请参阅 README 文件
【发布时间】:2021-04-04 23:02:19
【问题描述】:

我有这个代码:

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()

一直报这个错误:

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.

但我不知道为什么。Tesseract-ocr 二进制文件已成功安装并添加到我的 PATH 中。 我知道这一点,因为如果我在它给出的任何目录中运行 tesseract --version

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

【问题讨论】:

  • 你安装了 PyPi 包吗? pypi.org/project/pytesseract
  • 只是检查但是..当你运行 tesseract --version 你是否已经在这个目录中 C:\Program Files (x86)\Tesseract-OCR\ ?
  • @user3250052 no.我说'任何目录'
  • 哦,是的。对不起。如果您像这样明确传递路径,它会起作用吗 tss.pytesseract.tesseract_cmd = r''
  • @user3250052 是的。我已经得到它 2 分钟 b4 你发送了你的答案。你想回答它所以我会投票并接受你的答案吗?

标签: python


【解决方案1】:

像这样显式传递路径

tss.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 2020-08-26
    • 1970-01-01
    • 2014-03-25
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多