Hello, I need help debugging a PDF2Image & Poppler problem. I store my code on GitHub and have done everything correctly (to my knowledge) so far, and my Streamlit website successfully displays my PDF files as images when I run them locally. However, when I tried deploying it, I got these errors from the āManage Appā tab.
Traceback (most recent call last):
...
FileNotFoundError: [Errno 2] No such file or directory: 'poppler-24.02.0/Library/bin/pdfinfo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
I have looked at previous posts regarding this problem and did all the following:
Putting pdf2image and the other libraries that I need under requirements.txt
Putting packages.txt in the same directory as my script and writing poppler-utils inside.
Specifying poppler_path = r'poppler-24.02.0/Library/bin' under convert_from_path.
On top of 3, I specified the bin directory to my PATH system variable.
Even then, I am still getting the error above. Please help me resolve this problem and let me know if you need any additional information. Thank you very much for your help and time!
Hereās the library that I imported and code that I used:
from pdf2image import convert_from_path
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
...
def pdf_to_images(pdf_path):
# Convert PDF to a list of Pillow images
pop_path = r'poppler-24.02.0/Library/bin'
images = convert_from_path(pdf_path,500,poppler_path = pop_path)
return images
If packages.txt exists in the root directory of your repository we automatically detect it, parse it, and install the listed packages.
It is not obvious to me that packages.txt in any other location will be taken into account. The logs should tell you whether poppler-utils was installed or not.
That path looks wrong to me. How did you come to that?
The os.environ["PATH"] system variable? The same directory as in item 3? I donāt think you need items 3 and 4. The poppler executables should be in the right place already.
The docs suggests it should be in the root directory, you said you put it in the same directory as the script. These are not necessarily the same place.
poppler-utils
Putting it in requirements.txt should install the Pypi package. Putting it in packages.txt should install the Debian package (as long as the file is in the right place).
The text you pasted from the logs shows that the Pypi package was installed but it says nothing about the Debian package. In any case you need to figure out which one is what you need.
poppler_path
The path still looks wrong to me. And I still donāt know how you came to that.
PATH system variable
It is a bit unclear what you are doing here, but it doesnāt look right either.
If I had to guessā¦
You need the Debian package (put poppler-utils in packages.txt)
You donāt need the Pypi package (donāt put poppler-utils in requirements.txt)
You donāt need to explicitly set convert_from_path or any system variables.
Nevermind, I finally figured it out and got pdf2image and poppler to work when I deployed my app.
I did put the packages.txt (which contains poppler-utils) in the root directory of my repository along with my script, so everything is good there.
Previously, when I was working on this, I kept getting the exception:
Unable to get page count. Is poppler installed and in PATH?
The solution I found was to specify the bin folder under the poppler file I downloaded to my system PATH variable. Initially, it did not work, so to resolve this problem, I had to specify the poppler_path when I called the convert_from_path function like so:
My code ran without errors locally but faced issues like I mentioned when I tried to deploy my app. It turns out my app did not recognize when I specified poppler_path under convert_from_path. So, I had to get my system PATH variable working, and when it did, my app finally ran without errors.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking āAccept allā, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.