'pyinstaller icon not changing for the executable file

I have the app.py in root folder and favicon.ico in images/favicon.ico

When I create an executable file with pyinstaller

pyinstaller --onefile --icon=images/favicon.ico app.py 

The app executable is just showing the Mac's own icon for an executable file. I have tried changing the app name and moving the file to another directory as suggested in another question. I am on a Mac OS with latest Monterey, and latest Python. What can I do?



Solution 1:[1]

.ico files are for Windows.

For MacOs according to the documentation you have to use the icns file extension.

https://pyinstaller.readthedocs.io/en/stable/usage.html#cmdoption-i "FILE.icns: apply the icon to the .app bundle on Mac OS"

Solution 2:[2]

The documentations says: "When you build a windowed Mac OS X app (that is, running in Mac OS X, you specify the --onefile --windowed options), the spec file contains an additional statement to create the Mac OS X application bundle, or app folder:"

So I added the --windowed option and now the icon shows!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peterrabbit
Solution 2 AppCreator