Belval / pdf2image

A python module that wraps the pdftoppm utility to convert PDF to PIL Image object
MIT License
1.6k stars 194 forks source link

Adding conda poppler to PATH #265

Open 2V3EvG4LMJFdRe opened 1 year ago

2V3EvG4LMJFdRe commented 1 year ago

I'm trying to get poppler installed on macOS. brew install poppler seems to get stuck, so I've installed it through conda, but because I'm unfamiliar with conda, I have no idea how to specify the pages = convert_from_path(filepath, poppler_path=r"actualpoppler_path") line.


As it is now:

/usr/local/bin/python3 <<'EOF' - "$@"

from pdf2image import convert_from_path, convert_from_bytes

from pdf2image.exceptions import (
    PDFInfoNotInstalledError,
    PDFPageCountError,
    PDFSyntaxError
)

import tempfile

with tempfile.TemporaryDirectory() as path:
    images_from_path = convert_from_path('/Users/test.pdf', output_folder=path)
    # Do something here

EOF

The script naturally warns me

The action “Run Shell Script” encountered an error: “Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 568, in pdfinfo_from_path
    proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 13, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 127, in convert_from_path
    page_count = pdfinfo_from_path(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 594, in pdfinfo_from_path
    raise PDFInfoNotInstalledError(
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?”
2V3EvG4LMJFdRe commented 1 year ago

Solved for me, I ended up installing with brew. It took centuries, I'd never seen it happen before. I basically forgot I had the window running and came the next day to see poppler had been installed.