mikkelræv
mikkelræv

Reputation: 33

Pyinstaller - how to include a folder of images?

I've been stuck for hours trying to figure out how I can get Pyinstaller to include images. I've made a small tkinter script which load up some images to display. The program works on my own pc, but I want to be able to download the script on another computer and run it with the pictures working, but I can't figure out how to do that. I thought I could fix this issue by downloading a folder with the images on another machine and make the script refer to that folder but somehow it's just not working. It works when I run it on my own machine but not when I make it a .exe file with Pyinstaller.

os.chdir(sys.path[0])
path = os.path.dirname(os.path.abspath(__file__)) + r"\pics"

The thought behind the two lines above was that if I download the script on another computer as well as the pictures and insert them into a folder, I could refer to that folder and load them up (as long as the folder is in the same directory as my script) - but this isn't working. I'm clearly overseeing something, please help.

Upvotes: 2

Views: 557

Answers (1)

Legorooj
Legorooj

Reputation: 2757

The easiest way is to use the Tree class available in a spec file. See https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#the-tree-class for the official documentation and https://stackoverflow.com/a/20677118/10475068 for an example of how to use it.

Upvotes: 1

Related Questions