我在macOS 10.14.6上使用python3.7.4
,我正在尝试使用pdf2image
将pdf文件转换为图像。所以我已经安装了带有Homebrew
poppler
.我在尝试转换 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?
我在Google Colab上遇到了这个问题,我已经用这个命令修复了:
!apt-get install poppler-utils
我遇到了类似的问题,并在这里找到了答案: https://github.com/Belval/pdf2image/issues/101
SamikhaAgarwal说的是:
"这些pdf2image和pdftotext库的后端要求是Poppler,所以你必须安装。
conda install -c conda-forge poppler
然后错误将得到解决,如果它仍然对您不起作用,那么您可以按照 http://blog.alivate.com.au/poppler-windows/安装此库。
也许可以尝试:
brew install poppler
这对我有用。