Search code examples
imageiconspyqtcx-freeze

Icon not showing in PyQt application exe when built using cx_Freeze


I know this has been asked a bunch of times in this forum, but I really can't get my application icon to work when I build my PyQt application into a working exe-file using cx_Freeze.

I have copied the Qt image plugins (qico4.dll, qjpeg4.dll, etc.) into appdir/imageformats and also into appdir. I copied qt.conf to those dirs too. Changed the paths to it and nothing. This was suggested in some topic.

I tried to set the icon-option in a number of ways with setup.py-file and also without it.

I tried to create a resource file using qt designer and convert it. I tried to set the icon using qt designer to my mainwindow. Still nothing.

This is now my setup.py script:

import sys

from cx_Freeze import setup, Executable

base = None
if sys.platform == "win32":
    base = "Win32GUI"

executables = [
    Executable(
        "main.py",
        base = base,
        icon = "icon_64x64.ico",
        appendScriptToExe = True,
        appendScriptToLibrary = False,
        targetName = "MyApp.exe")
]

buildOptions = dict(
    create_shared_zip = False)

setup(
    name = "MyApp",
    version = "1.0",
    options = dict(build_exe = buildOptions),
    executables = executables)

Solution

  • The application icon isn't something Qt manages - it's embedded into the exe file for the operating system to read.

    Check that icon_64x64.ico exists in the same folder that you're running setup.py from, and that it's a valid ico file. For comparison, here's a setup.py that works with an icon.