ocrmypdf - 无法找到 source-pdf?

ocrmypdf - could not find source-pdf?

我想使用 ocrmypdf 将一些 pdf 文件从图片转换为可读的 pdf -

尝试使用以下简单代码: (invoice.pdf 当然可以在与 python 脚本相同的路径中使用,并且应该生成 output.pdf)

import ocrmypdf
if __name__ == '__main__':
  fn = r"C:\Users\Polzi\Documents\DEV\Python-Diverses\PDFOCR\invoice.pdf"
  ocrmypdf.ocr(fn, 'output.pdf', deskew=True)

但不幸的是我收到了这个错误信息:

$ python exPDFOCR.py
[WinError 2] Das System kann die angegebene Datei nicht finden
Traceback (most recent call last):
  File "C:\Users\Polzi\Documents\DEV\Python-Diverses\PDFOCR\exPDFOCR.py", line 25, in <module>
    ocrmypdf.ocr('invoice.pdf', 'output.pdf', deskew=True)
  File "C:\Users\Polzi\Documents\DEV\.venv\testing\lib\site-packages\ocrmypdf\api.py", line 336, in ocr
    check_options(options, plugin_manager)
  File "C:\Users\Polzi\Documents\DEV\.venv\testing\lib\site-packages\ocrmypdf\_validation.py", line 271, in check_options
    ocr_engine_languages = plugin_manager.hook.get_ocr_engine().languages(options)
  File "C:\Users\Polzi\Documents\DEV\.venv\testing\lib\site-packages\ocrmypdf\builtin_plugins\tesseract_ocr.py", line 155, in languages
    return tesseract.get_languages()
  File "C:\Users\Polzi\Documents\DEV\.venv\testing\lib\site-packages\ocrmypdf\_exec\tesseract.py", line 143, in get_languages
    proc = run(
  File "C:\Users\Polzi\Documents\DEV\.venv\testing\lib\site-packages\ocrmypdf\subprocess\__init__.py", line 53, in run
    proc = subprocess_run(args, env=env, **kwargs)
  File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\polzi\appdata\local\programs\python\python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

为什么他在执行 py 文件的同一文件夹中找不到文件?

有时第一条错误消息可能会在没有明确原因的情况下产生误导

在这种情况下,主要消息 "The system cannot find the specified file"

会导致用户专注于为什么文件名不正确,就像在这种情况下一样。

报错应该是依赖中没有找到需要的文件。这可能是由于一个或多个 Tesseract 或相关的 Leptonica / Language 数据文件不在正确的位置引起的,原因可能是没有安装或安装不当。

据报道,https://github.com/UB-Mannheim/tesseract/wiki 在 windows 上安装了 tesseract,“脚本现在工作正常”

请注意,缺少依赖项是此处出现类似消息的原因