简体   繁体   中英

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. Poppler is installed (via homebrew) and the package via pip.

However, when running convert_to_path(my_pdf) I get the following:

    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

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.

Attempted to force the poppler path in convert_to_path with the following,

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 = "/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. Is it maybe because I am using pyenv too?

if you use conda environment run the below code in mac terminal

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

It solve the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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