【问题标题】:tesseract.exe is not installed or it's not in your pathtesseract.exe 未安装或不在您的路径中
【发布时间】:2020-04-10 04:43:45
【问题描述】:

我正在使用 Pytesseract 阅读 PDF 的特定部分。以下是我将 tesseract 配置到我的代码中的代码。

pytesseract.pytesseract.tesseract_cmd = os.path.join(cwd, "Tesseract-OCR\\tesseract.exe")

cwd 与我的 SplitPDF.py 文件和 Tesseract-OCR(包含 tesseract.exe)文件夹所在的目录相同。

当我执行 SplitPDF.py 时,一切正常,我得到了我想要的输出。 但是当我创建 SplitPDF.exe(使用 Pyinstaller)时出现问题,我收到一条错误消息,提示 tesseract.exe 未安装或不在您的路径中。

以下是完整的错误:

Traceback(最近一次调用最后一次):文件 “site-packages\pytesseract\pytesseract.py”,第 223 行,在 run_tesseract 文件“subprocess.py”,第 775 行,在 init 文件“subprocess.py”中, 第 1178 行,在 _execute_child FileNotFoundError: [WinError 2] 系统找不到指定的文件

在处理上述异常的过程中,又发生了一个异常:

Traceback(最近一次调用最后一次):文件“tkinter__init__.py”,行 1705,在 call 文件“PDF_Splitter.py”,第 241 行,在 UploadAction1 pdfsplitbylca(entryString) 文件“Split_by_LCA_1.py”,第 155 行,在 pdfsplitbylca text = pytesseract.image_to_string(im, lang = 'eng') 文件“site-packages\pytesseract\pytesseract.py”,第 345 行,在 image_to_string 文件“站点包\pytesseract\pytesseract.py”,行 344,在文件“site-packages\pytesseract\pytesseract.py”中,行 253,在 run_and_get_output 文件中 “site-packages\pytesseract\pytesseract.py”,第 225 行,在 run_tesseract pytesseract.pytesseract.TesseractNotFoundError: C:\Users\VADIRA~1.KAT\AppData\Local\Temp_MEI370202\Tesseract-OCR\tesseract.exe 未安装或不在您的路径中

我没有正确创建 .exe 还是有更好的方法来配置 Tesseract?

【问题讨论】:

    标签: python python-tesseract


    【解决方案1】:

    您应该考虑使用Pytesseract 库(tesseract python 库)而不是可执行文件。我希望这会有所帮助。使用非常简单。您必须先安装它,然后才能使用

    import pytesseract
    from PIL import Image
    
    pytesseract.image_to_string(Image.open('image'))
    

    希望对你有帮助

    【讨论】:

    • 我无法使用这种方式,因为我无法使用 pip 在我的 Windows 上安装 pytesseract。所以我将不得不手动安装它。因为它没有在全局变量中定义,所以我使用 pytesseract.pytesseract.tesseract_cmd 来配置它。
    猜你喜欢
    • 2019-01-11
    • 2018-11-29
    • 2020-08-26
    • 1970-01-01
    • 2018-04-17
    • 2017-03-15
    • 2018-09-12
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多