Vertana 0 Newbie Poster

I'm trying to turn my PyQt4 into a .exe in order to give it my end users. I'm so-so familiar with cx-freeze and I know how to use Innosetup. My problem is that when run from the command line my Qt application uses the icon correctly. After I freeze the package, the executable itself has the correct icon, however, once in the actual application... no icon in the top left corner. It's really bugging me because as far as I can tell me setup script is fine. I think I have to declare the icon specifically via the command line at setup run time, but when I tried it gave me the message that --icon must not have an argument.

Any help would be appreciated.
The setup script is:

from cx_Freeze import setup, Executable

import sys
include_files = [("icons","icons")]


Target_1 = Executable(
    # what to build
    script = "Launcher.py",
    initScript = None,
    base = 'Win32GUI',
    targetName = "Application.exe",
    compress = True,
    copyDependentFiles = False,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = "resources\icon.ico"
    )
setup(
        name = "PPT Photo Exporter",
        version = "0.1",
        description = "Exports Photos From a PPT to PNG.",
        author = "author",

    options = {"build_exe": {"include_files":include_files}
               },

    executables = [Target_1]
    )

I'm calling it from the command line like:

python setup.py build_exe --icon

The icon I am attempting to use is in (in relation to the .py files) ./icons/icon.ico

I'm not sure how I can make Qt see the icon once it's packaged by cx-freeze.
My line of code that actually uses the icon (which works before it is frozen):

self.setWindowIcon(QtGui.QIcon('reources/icon.ico'))

Dani AI

Generated

A few diagnostic notes first: the EXE-level icon (the file icon you see in Explorer) is a different thing from the window/titlebar icon Qt shows at runtime. If the EXE shows the icon but the running window does not, the runtime code that loads the .ico is the likely problem — common causes are a wrong path (typos or folder mismatch), backslash-escape mistakes in string literals, or the icon file not being where the frozen app expects it.

Practical fixes to try (in order of simplicity):

  • Fix any typos and avoid literal backslashes in paths. Prefer os.path.join so paths are platform-safe.
  • Make the runtime lookup robust so it works both when running frozen and when running from source. Resolve a base directory like the folder containing sys.executable when frozen, or file when not, and build the full path to the included icons folder.
  • Check that cx_Freeze actually copied the icons folder into the build directory and that the app can see the file at runtime (use os.path.exists or print the resolved path while debugging).
  • Set the application icon at QApplication startup (app.setWindowIcon(...)) before creating the main window so Windows will pick it up for the titlebar and taskbar.

If you want a file-less approach, embed the icon via Qt's resource system (.qrc) and compile it with pyrcc4; that makes the icon available as a :/ resource inside the binary and avoids runtime path headaches.

Quick checklist for : confirm the include_files mapping copies the icon, fix any folder/name mismatches, use a frozen-aware path resolver at runtime, ensure the ICO contains small sizes (16x16) for the titlebar, and set the icon on the QApplication before creating windows. This will resolve the mismatch between the EXE icon and the runtime window icon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.