简体   繁体   English

使用pyinstaller创建包含图片的包

[英]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. 我想从我的python脚本创建一个exe文件,但我想在包中添加一些图片。 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. 我不知道如何打开规范文件以及如何编辑它们以执行包含aditional文件的一个exe文件。 Please help me. 请帮我。

Thanks to everyone, who will respond. 感谢大家,谁会回应。

First of all you have to create a .spec file . 首先,您必须创建一个.spec文件 If you tried to run pyinstaller, it should have generated one already. 如果你试图运行pyinstaller,它应该已经生成了一个。 If you want to compile with the .spec file, you have to use the pyinstaller myspec.spec command. 如果要使用.spec文件进行编译,则必须使用pyinstaller myspec.spec命令。

You can edit the .spec file in any text editor to add your images as data . 您可以在任何文本编辑器中编辑.spec文件,以将图像添加为data Just add them as a list of tuples, including the source file and the target directory. 只需将它们添加为元组列表,包括源文件和目标目录。 As per the pyinstaller manual example: 根据pyinstaller手册示例:

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

This will add img01.jpg to the .exe folder. 这会将img01.jpg添加到.exe文件夹中。 If you set a relative directory, you need to make sure that your script looks at the correct relative location for these files. 如果设置了相对目录,则需要确保脚本查看这些文件的正确相对位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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