How to manually add PIL module to pyinstaller exe?

Viewed 2942

I am creating a standalone exe file with pyinstaller but I get the 'modulenotfound' error when I try to run it. It cannot locate the PIL module even though it is in the same 'site-packages' folder as all my other modules. How do I tell it where the PIL module is?

I have tried the following flags in my cmd line when using pyinstaller, none of them worked:

--hidden-import=Pillow
--hidden-import='PIL'
--hidden-import='Pillow'

My script uses the following line of code in regards to the PIL module:

    from PIL import Image, ImageTk

Everything works fine in the script, it is only when I use pyinstaller that I have a problem.

3 Answers

I found a solution: I had to install pyinstaller within the PyCharm terminal, then I had to run pyinstaller within the PyCharm terminal as well using

pyinstaller --onefile -w "foo.py"

I was previously running a cmd right from my file directory outside of PyCharm and running pyinstaller there, but running pyinstaller inside PyCharm works.

I just copied the library folder of PIL from the Python folder within the drive and move it to the same folder as the .py file, then I run the cmd with the line --hidden-import=PIL and it just works, just remember to put the executable file in the same directory you put within your line of codes, might not run if it's not in the same directory.

To whom might help I got lots of issues trying to user pymssql with Pyinstaller and I finally got it right so posting here might help someone after you install pymssql using pip install pymssql

use this parameters in pyintaller to get it included

--onefile --paths=.\venv\ --hidden-import='pymssql' --hidden-import='uuid' --collect-all='pymssql' --collect-all='uuid'
Related