Search code examples
pythonpyinstallerpypdf

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?


Solution

  • 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)