首页 > 解决方案 > Mac Poppler + pdf2image 路径错误

问题描述

问题: 我一直在尝试使用 Python 库 pdf2image,我知道它需要预先安装 poppler。Poppler 已安装(通过自制软件)并通过 pip 安装软件包。

但是,在运行时,convert_to_path(my_pdf)我得到以下信息:

    Traceback (most recent call last):

  File "<ipython-input-9-ba107659b495>", line 1, in <module>
    test_image = convert_from_path(testfile,

  File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 97, in convert_from_path
    page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]

  File "/Users/<myuser>/.pyenv/versions/3.8.0/lib/python3.8/site-packages/pdf2image/pdf2image.py", line 467, in pdfinfo_from_path
    raise PDFInfoNotInstalledError(

PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

我的系统:Mac,OC 10.15.7 Python(通过 Homebrew)版本 3.8.0

which python
/Users/<myuser>/.pyenv/shims/python
which pip
/Users/<myuser>/.pyenv/shims/pip

到目前为止我已经尝试过:Poppler 是通过自制软件 安装的brew install popplerpip3 install pdf2imagebrew cleanup

尝试使用以下命令强制 convert_to_path 中的 poppler 路径,

pop_path = "/usr/local/Cellar/poppler/21.03.0_1"
convert_to_path(my_pdf_file,poppler_path = pop_path)

但仍然得到同样的错误。

在网上看了一下,发现很多人有类似但不完全相同的问题。我觉得我一定做错了什么,所以任何指导都会很棒。

标签: pythonmacoshomebrewpoppler

解决方案


部分解决方案?

在手动输入 pop_path 文件路径时,我忘记将 /bin 附加到路径中,

pop_path = "/usr/local/Cellar/poppler/21.03.0_1/bin"

该代码现在有效。虽然我的自尊需要一段时间才能恢复...

我觉得我可能仍然坐在一个糟糕的配置问题上?关于类似问题的许多帖子似乎暗示自制软件安装的popper不应该有这个问题。可能是因为我也在使用 pyenv 吗?


推荐阅读