Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PyInstaller and include window icon

I have set the icon for my PyQt application using self.setWindowIcon(QtGui.QIcon('icon.png')) and it works fine when I run my code in PyCharm.

Next I converted my application to one file with PyInstaller:

pyinstaller.exe --onefile --windowed opc.py --name myapps

However, when running the executable the icon is not shown. What am I doing wrong ?


On left site code from PyCharm, on right site from one file (pyinstaller.exe --onefile --windowed opc.py --name myapps). Why is not the same ? I want *.png icon because is transparent.

enter image description here

like image 879
Luk Avatar asked May 19 '16 11:05

Luk


1 Answers

The icon displayed when running an executable on Windows comes from the executable file itself. To bundle an icon with your application you need to specify the icon when building with pyinstaller.exe by passing the --icon parameter. For example:

pyinstaller.exe --onefile --windowed --name myapps --icon=icon.ico opc.py

Note that unlike for setWindowIcon() the icon file must be in .ico format, so you will need to convert it from the .png first.

If you want to use the PyQt call to set the icon you will need to bundle the icon file into the executable, which can be done using a PyInstaller spec file. A walkthrough of the process of creating and modifying the spec file is in this previous answer.

like image 125
mfitzp Avatar answered Oct 27 '22 00:10

mfitzp