Reputation: 831
I'm building a Windows one file executable of my wxPython app with Pyinstaller. I want to add a window icon and doing pyinstaller --icon=test.ico --onefile --noconsole test.pyw
is perfectly fine only if I put the test.ico file just next to the builded executable. This makes me distribute both the exe and the icon, and that's at least uncomfortable.
I also do
icon = wx.EmptyIcon()
icon.CopyFromBitmap(wx.Bitmap("test.ico", wx.BITMAP_TYPE_ANY))
self.SetIcon(icon)
in my wxPython app.
My research says a suggestion to hardcode a base64 string representation of the icon but it's an insanely long string as I also need to print on paper my code. I saw this other post and I sense it has my answer but I just don't understand it.
So. How can I embed the icon to the exe?
EDIT: .spec
file
# -*- mode: python -*-
block_cipher = None
a = Analysis(['test.pyw'],
pathex=['D:\\test'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='test',
debug=False,
strip=False,
upx=True,
console=False , icon='test.ico')
Upvotes: 0
Views: 2434
Reputation: 3177
First, with --icon
option you already have included the .ico
into your executable. But wxPython has no way to extract it from the .exe
(I suppose it would not be all that hard by using windows system calls, but that is not the point).
Therefore you have to include the .ico
-file a second time, this time into the file system.
The stackoverflow article linked by you already has the answers:
Modify the .spec
file to include the icon file into the bundled application.
When running the application, it will decompress the bundled files in a temporary location. As pointed out in the article referenced by you, the resource path is specified in sys._MEIPASS
. Do not forget to consider subdirectories (e. g. a images
for ./images/icon.ico
) when forming the full file qualifier.
Show your .spec
file modification and the code retrieving the icon to get further help
Upvotes: 1