PyInstaller icon option doesn't work on Mac


I ran the following command on my mac and created an .app file.

pyinstaller --icon icon.icns --noconsole -n testApp

However, the generated .app file does not show the icon.

enter image description here

icon.icns is specified as an icon file in info.plist.

enter image description here

The Content/Resouces folder contains icon.icns.

enter image description here

When I run the .app file, I see an icon on the Dock.

However, the icon is not reflected in the .app file itself. Why is this?


You should use the command for creating a macOS app bundle

If specified correctly, the icon.icns will be copied into the Resources folder and applied to the bundle in the dist directory, after running the pyinstaller command. (don’t try .ico as suggested, that’s for Windows).

I just tried creating a simple Python app using PySide2, and it included the icon file in the app bundle with no problems.

Given that the icon.icns is in the same directory as

Your command should be:

$ pyinstaller --onefile --windowed --icon icon.icns --name testApp

This will produce the app bundle, and you should be able to run it just fine.

But wait, there is even more…

Sadly, the story doesn’t quite end here.


To do things "the right way" and make macOS happy, you should also include the:

--osx-bundle-identifier 'YOUR_IDENTIFIER'

That way the spec file will include the info for the Info.plist file that gets produced.

Also there should be a section in the spec file describing the Info.plist contents, something in the lines of:

app = BUNDLE(exe,
            'NSPrincipalClass': 'NSApplication',
            'NSAppleScriptEnabled': False,
            'CFBundleDocumentTypes': [
                    'CFBundleTypeName': 'My File Format',
                    'CFBundleTypeIconFile': 'MyFileIcon.icns',
                    'LSItemContentTypes': ['com.example.myformat'],
                    'LSHandlerRank': 'Owner'

In the above example, the key/value
'NSPrincipalClass': 'NSApplication'
is necessary to allow Mac OS X to render applications using retina resolution.

The key 'NSAppleScriptEnabled' is assigned the Python boolean False, which will be output to Info.plist as <false/>. Finally the key CFBundleDocumentTypes tells Mac OS X what file-types your application supports, if any.

Answered By – C. Sederqvist

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published