在Pyinstaller中将图像添加到.spec文件 [英] Add image to .spec file in Pyinstaller
问题描述
有人知道如何修改使用Pyinstaller的 Makespec.py
创建的 .spec
文件,以便它包含 _MEIPASS2
Temp目录中的图像数据?我希望能够为我的exe添加一个图标。我已经完成了这里的,但我只是我不知道如何在 .spec
中添加我的数据。
Does anybody know how to modify the .spec
file created with the Makespec.py
of Pyinstaller such that it includes an image data in the _MEIPASS2
Temp dir? I want to be able to add an icon to my exe. I've done what's written here, but I just don't know how to add my data in the .spec
.
我最后添加这一行 .spec
文件:
I'm adding this line in the end of the .spec
file:
a.datas += [('iconName.ico','DATA','C:\\Python26\\pyinstaller-1.5.1\\iconName.ico')]
推荐答案
这是我的spec文件( Collector.spec
)I用于一个简单的python程序,名为Collector.py
。
Here is my spec file (Collector.spec
) I used for a simple python program called "Collector.py"
.
# -*- mode: python -*-
a = Analysis(['Collector.py'],
pathex=['C:\\Users\\vijay\\Python\\Collector'],
hiddenimports=[],
hookspath=None,
runtime_hooks=None)
a.datas += [('logo.png','C:\\Users\\vijay\\System\\icon\\logo.png','DATA')]
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='Collector.exe',
debug=False,
strip=None,
upx=True,
console=False , icon='C:\\Users\\vijay\\System\\icon\\logo.ico')
该行a.datas + = ....
就在pyz变量上面,它保存了png图像的路径,该图像将显示在我的GUI应用程序的各个窗口上。
在exe变量中设置的icon = ....
变量,保存ico图像的路径,该图像将作为桌面图标显示在Windows桌面上。
The line "a.datas += .... "
just above pyz variable holds the path to png image that will be displayed on various windows of my GUI application.
The "icon=...."
variable set inside exe variable, holds the path to ico image that will be displayed on Windows Desktop as the Desktop Icon.
您现在可以使用Max在您的此处中所做的工作主程序( Collector.py
,对我而言)。
You can now use what Max has done here in your main program (Collector.py
, for me).
这是我脚本的片段 Collector.py
,其中我使用了 Max 的代码:
Here is a snippet of my script Collector.py
, where I've made use of Max's Code:
path = self.resource_path("logo.png")
icon = wx.Icon(path, wx.BITMAP_TYPE_PNG)
self.SetIcon(icon)
现在,当我运行 pyinstaller Collector.spec
,我有一个桌面图标和我的收藏家应用程序窗口的图标。
Now, when I run pyinstaller Collector.spec
, I have both a Desktop Icon and an Icon for my Collector App windows.
希望这有帮助!
这篇关于在Pyinstaller中将图像添加到.spec文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!