简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM