【问题标题】:ocrmypdf - could not find source-pdf?ocrmypdf - 找不到源pdf?
【发布时间】:2022-01-16 03:26:27
【问题描述】:

我想使用 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 文件的文件夹中找不到该文件?

【问题讨论】:

  • 当我尝试时:ocrmypdf.ocr("invoice.pdf", 'output.pdf',deskew=True) 它给了我与上面完全相同的错误消息......
  • 用这个也试过了:ocrmypdf.ocr('invoice.pdf', 'output.pdf', deskew=True) 相同的结果/错误消息...
  • 您好 - 从这里在 Windows 上安装 tesseract 后:github.com/UB-Mannheim/tesseract/wiki 脚本现在可以正常工作了感谢您的帮助!
  • 当您将解决方案添加为答案时 - 如果您愿意,我会将其标记为解决方案。

标签: python pdf ocr pdfplumber ocrmypdf


【解决方案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

【讨论】:

    猜你喜欢
    • 2021-05-29
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    • 2022-07-14
    相关资源
    最近更新 更多