pdf2image not working with gunicorn/flask

316 views Asked by At

For the past day I have been trying to incorporate pdf2image into my flask webservice. The problem is, whatever I do, I still get the "Is poppler installed and in PATH?" error message. I have written a little program that just prints the number of pages in a pdf file. This works completely fine, inside and outside the venv containing flask. If I try to do this from the flask file, I get the error. I even tried calling the very same function in the test code, but to no avail. I don't really know what to do anymore, so any help is greatly appreciated.

P.S.: I don't really know what source to include for this post, so just feel free to ask and I will provide it.

1

There are 1 answers

3
PhiM On BEST ANSWER

I had the symptoms which you describe. For me the problem was the following:

in the .service file used by systemd to start gunicorn, I had an incomplete path variable. The solution was to add the path to pdftoppm and pdftocairo, which in my case (on Debian 10) was /usr/bin The solution is therefore that the .service file includes

[Service]
...
Environment="PATH=<your_app_path>/venv/bin:/usr/bin"

Note: This problem and its solution are thus broader than a pdf2image issue, but it seems to show up frequently with pdf2image... assuming this is true, I hope that your question and my response are both relevant.