PyInstaller puts its own icon on every .exe it builds unless you give it one.
You set yours with the --icon option, short form -i.
Here is how to prepare the file, pass it to PyInstaller and check that it worked.
1. Prepare a multi-size .ico
Start from a square PNG, 256×256 px or larger, with a transparent background. Convert it with the PNG to ICO converter to get one .ico holding nine sizes, from 16 to 256 px.
Name it something simple, such as app.ico, and put it next to your script.
Why not pass the PNG directly? Recent PyInstaller versions can convert a PNG for you, but only if Pillow is installed, and you don't control how the small sizes come out. A ready-made ICO gives the same result on every build machine.
2. Build with --icon
pyinstaller --onefile --windowed --icon=app.ico main.py
--windowed is for GUI apps; leave it out for console tools. The icon option works the same either way.
If you want no icon at all, so Windows shows its generic one, pass --icon=NONE.
3. Or set it in the .spec file
If you build from a spec file, the icon goes in the EXE section. Running PyInstaller with --icon once writes this line for you.
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
name='MyApp',
console=False,
icon='app.ico',
)
4. The window icon (Tkinter, PyQt)
The .exe icon is what Explorer and the taskbar show for the file. The icon in your window's title bar is set by your GUI toolkit:
- Tkinter:
root.iconbitmap('app.ico') - PyQt / PySide:
app.setWindowIcon(QIcon('app.ico'))
With --onefile, bundle the .ico as data (--add-data) and load it from the bundle's temporary folder at runtime, or the window falls back to the default icon.
5. Check the result
Open the dist folder and look at the .exe in Explorer with large or extra large icons. You should see your icon, sharp at every view size.
If you still see the old icon, it's almost always Windows' icon cache, not your build. Rename the .exe or follow the icon cache fix.
Related guides
- Windows icon sizes: which ones an .ico should contain
- Set the icon of an Inno Setup installer
- ICO not working? Fixes for the most common problems
Make app.ico for your PyInstaller build
Convert a PNG