简体   繁体   中英

Creating a bundle including a pictures with pyinstaller

I want to create a exe file from my python script, but I want to add some pictures to the bundle. I do not know how to do it. I researched but the answer was not anywhere. I do not know how to open the spec files and how to edit them to do a one exe file including a aditional files. Please help me.

Thanks to everyone, who will respond.

First of all you have to create a .spec file . If you tried to run pyinstaller, it should have generated one already. If you want to compile with the .spec file, you have to use the pyinstaller myspec.spec command.

You can edit the .spec file in any text editor to add your images as data . Just add them as a list of tuples, including the source file and the target directory. As per the pyinstaller manual example:

a = Analysis(...
     datas=[ ('src/img01.jpg', '.') ],
     ...
     )

This will add img01.jpg to the .exe folder. If you set a relative directory, you need to make sure that your script looks at the correct relative location for these files.

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