简体   繁体   English

Mac Poppler + pdf2image 路径错误

[英]Mac Poppler + pdf2image PATH bug

Problem: I've been attempting to use the Python library pdf2image, which I am aware requires the prior installation of poppler.问题:我一直在尝试使用 Python 库 pdf2image,我知道它需要事先安装 poppler。 Poppler is installed (via homebrew) and the package via pip. Poppler 已安装(通过自制软件),package 通过 pip 安装。

However, when running convert_to_path(my_pdf) I get the following:但是,在运行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?

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

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

What I've tried so far: Poppler is installed via homebrew ( brew install poppler ) and pdf2image installed with pip3 install pdf2image I've run brew cleanup too.到目前为止我已经尝试过: Poppler 是通过自制软件安装的( brew install poppler )和 pdf2image 安装pip3 install pdf2image我也运行了brew cleanup

Attempted to force the poppler path in convert_to_path with the following,尝试使用以下内容在 convert_to_path 中强制使用 poppler 路径,

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

but still get the same error.但仍然出现相同的错误。

Had a decent look online and found many people with similar, yet not identical, problems.上网查了一下,发现很多人都有类似但不完全相同的问题。 I feel like I must be doing something wrong, so any guidance would be great.我觉得我一定做错了什么,所以任何指导都会很棒。

Partial Solution?部分解决方案?

In manually entering the pop_path file path, I forgot to append /bin to the path,在手动输入pop_path文件路径时,忘记把append /bin到路径,

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

The code works now.该代码现在有效。 Though my pride will take some time to recover...虽然我的自尊需要一段时间才能恢复...

I feel like I might still be sitting on a bad configuration issue?我觉得我可能仍然坐在一个糟糕的配置问题上? The many posts on similar issues seem to imply a homebrew installed-popper shouldn't have this issue.关于类似问题的许多帖子似乎暗示自制软件安装的popper不应该有这个问题。 Is it maybe because I am using pyenv too?可能是因为我也在使用 pyenv 吗?

if you use conda environment run the below code in mac terminal如果您使用 conda 环境,请在 mac 终端中运行以下代码

conda install -c conda-forge pdf2image
conda install -c conda-forge poppler

It solve the problem它解决了问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM