【发布时间】:2019-08-21 09:01:50
【问题描述】:
我在 macOS 10.14.6 上使用 python 3.7.4 并尝试使用 pdf2image 将 pdf 文件转换为图像。所以我安装了poppler 和Homebrew。当我尝试转换 PDF 时收到错误消息。
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 240, in _page_count
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo': 'pdfinfo'
我使用以下代码:
from pdf2image import convert_from_path, convert_from_bytes
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
images = convert_from_path('test.pdf')
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "/Users/michelebutturini/Desktop/Segmentation.py", line 16, in <module>
images = convert_from_path('test.pdf')
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 54, in convert_from_path
page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 244, in _page_count
raise PDFInfoNotInstalledError('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?
【问题讨论】:
-
Is poppler installed and in PATH?- 你的PATH设置正确吗? -
嗨,Kampi,这是路径:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks /Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/版本/当前/命令,这是 poppler 是:/usr/local/Cellar/poppler/0.79.0 我如何知道我的 PATH 是否设置正确?谢谢
-
尝试安装 poppler 内部使用的“poppler-utils”来获取 pdf 中的页数。
标签: python-3.x macos homebrew poppler