Yahav Festinger
Yahav Festinger

Reputation: 1125

PyPDF2 with PyInstaller

I tried convert python script into exe using pyinstaller, so I ran the following command: pyinstaller --onefile app.py, and it seems that the exe file created successfully, but when I tried running the exe an error occurred: ModuleNotFoundError: No module named 'PyPDF2'.

I read that pyinstaller doesn't see second level imports, so I ran the following command: pyinstaller --hidden-import PyPDF2 --onefile app.py, but the error remains the same.

Do you have any solution for this problem?

Upvotes: 0

Views: 845

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113950

i just made an exe with pypdf2 in it using pyinstaller (literally a few days ago) ... i import it at the top of my main file and it bundled in just fine

my guess as to the issue is that PyPDF2 is not installed in the python that you are getting using pyinstaller

first open a terminal and run python myscript.py and make sure it runs correctly with that version of python

next run python -m pyinstaller --onefile myscript.py this will ensure that it is using the correct python version (the one with pyPDF2 installed)

(at the top of myscript.py make sure to import PyPDF2)

Upvotes: 1

Related Questions