【发布时间】:2020-03-09 00:22:30
【问题描述】:
使用Poppler 进行部分 PDF 渲染和转换,我有以下代码,但执行代码最终出现错误,如下所述。
错误消息:pdf2image.exceptions.PDFInfoNotInstalledError:无法 获取页数。 poppler 是否已安装并在 PATH 中?
我已将 Poppler 路径添加为环境变量,但错误仍然存在。
import tempfile,os
with tempfile.TemporaryDirectory() as path:
images_from_path = convert_from_path("C:\\Users\\mehak\\OneDrive\\Desktop\\iffco.pdf")
index = 1
for image in images_from_path:
image.save("C:\\Users\\mehak\\OneDrive\\Desktop" + str(index) + ".jpg")
index += 1```
```Traceback (most recent call last):
File "C:\Users\mehak\AppData\Local\Programs\Python\Python37\lib\site-packages\pdf2image\pdf2image.py", line 355, in _page_count
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
File "C:\Users\mehak\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\mehak\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testing_ocrpdf.py", line 7, in <module>
images_from_path = convert_from_path('D:\\iffco.pdf')
File "C:\Users\mehak\AppData\Local\Programs\Python\Python37\lib\site-packages\pdf2image\pdf2image.py", line 82, in convert_from_path
page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
File "C:\Users\mehak\AppData\Local\Programs\Python\Python37\lib\site-packages\pdf2image\pdf2image.py", line 360, in _page_count
"Unable to get page count. Is poppler installed and in PATH?"
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?```
【问题讨论】:
-
这是非常具体的上下文错误。这个 testing_ocrpdf.py 位于哪里?你能发布完整的代码吗?你能检查一下你是否安装了 poppler-utils 吗?
-
现在我已将代码放在文档文件夹中并提到了上面的完整代码并尝试安装 poppler-utils 但出现此错误:
-
C:\Users\mehak\Documents>pip install poppler-utils 错误:找不到满足 poppler-utils 要求的版本(来自版本:无)错误:没有找到 poppler 的匹配分发-utils
-
要使用 poppler,您需要在您的机器和路径中安装 poppler-utils。 github.com/Belval/pdf2image/blob/master/README.md
-
我已经安装了“poppler-0.51”并在 env var 中添加了与 poppler_path 相同的内容:“C:\Program Files\poppler-0.51_x86\poppler-0.51\bin”但得到了相同的结果错误