How to use pyinstaller to include images in the .exe

I am trying to make a simple pathfinding app with pygame and make it a .exe using pyinstaller. Unfortunatly, the project uses images, and when I run the .exe, it comes back with telling me the images dont exist. How do I run pyinstaller to include the images?


Solution 1:

If you dont use the --onefile command, you can just drag and drop the images into the folder your exe is in. Or drop in the folder of images.

If you do use onefile, you need to modify the .spec file you get when you run the code pyinstaller script.py. Then run pyinstaller scriptname.spec. edit the datas variable somewhat like this

datas = [('src/image.png', '.'),
         ('src/image1.png' '.')]

If the images are in a different folder than your script you put the address of where they're at in regards to the script.

more information can be read in the documentation