I have several Python scripts which use pypdfium2 library. They work correctly when I run them with Python. But when I pack them into “.exe” using pyinstaller and try to run them, I get the below error:
Traceback (most recent call last):
File "app.py", line 3, in <module>
File "PyInstallerloaderpyimod02_importers.py", line 419, in exec_module
File "pypdfium2__init__.py", line 7, in <module>
File "PyInstallerloaderpyimod02_importers.py", line 419, in exec_module
File "pypdfium2_helpers__init__.py", line 4, in <module>
File "PyInstallerloaderpyimod02_importers.py", line 419, in exec_module
File "pypdfium2_helpersunsupported.py", line 8, in <module>
File "PyInstallerloaderpyimod02_importers.py", line 419, in exec_module
File "pypdfium2raw.py", line 495, in <module>
File "pypdfium2raw.py", line 183, in __call__
ImportError: Could not load pdfium.
[10640] Failed to execute script 'app' due to unhandled exception!
I read in the thread below that additional data needs to be supplied when I am packing a python script using pypdfium2. The answer lists paths to files which need to be added:
pdfium library is not working when compiling my code in python
However, it seems to me that something changed in the meantime (new version of pypdfium was released on May 9 this year), and I can no longer find the files listed in the above answer (‘version.json’ file is no longer in libsite-packagespypdfium2_raw).
Does anyone have a solution?
Example code which fails when packed into .exe:
import pypdfium2 as pdfium
pdf_path = input('Enter the path of the PDF file: ')
pdf_images = pdfium.PdfDocument(pdf_path)
# rest of code goes here