1

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

使用以下简单代码进行了尝试:(invoice.pdf 当然可以在与 python-script 相同的路径中使用,并且应该生成 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 文件的同一文件夹中找到该文件?

4

1 回答 1

1

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

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

将引导用户专注于文件名不正确的原因,如本例所示。

错误应该报告的是未找到依赖项中的必需文件。这可能是由于一个或多个 Tesseract 或相关的 Leptonica / Language 数据文件由于未安装或安装不当而不在正确位置引起的。

据了解,从https://github.com/UB-Mannheim/tesseract/wiki “脚本现在可以正常工作”在 Windows 上安装 tesseract

请注意,缺少依赖项是此处出现类似消息的原因Import ocrmypdf in Visual Stdio Code in Python

于 2022-01-15T19:26:27.100 回答