Search code examples
python-3.xcx-freeze

cx freeze set custom .exe icon


I am converting a .py file to a .exe file using cx_freeze. My current setup file is working but I can not seem to change it so that my .exe file has the custom icon I have made. I have tried a few different ways and none of them seem to be working. Any advice would be very helpful. Thank you for your time.

Attempt one

import sys
from cx_Freeze import setup, Executable

include_files = ['autorun.inf']

base = None

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

setup(name = "Calculator",
        version = "0.1",
        description = "Simple Calculator",
        options = {'build_exe':{'include_files':include_files, 
                   'icon':'icon.ico'}},
        executables=[Executable("main.py", base = base)])

Attempt Two

import sys
from cx_Freeze import setup, Executable

include_files = ['autorun.inf']

base = None

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

setup(name = "Calculator",
        version = "0.1",
        description = "Simple Calculator",
        options = {'build_exe':{'include_files':include_files}},
        executables=[Executable("main.py", base = base, icon = 'icon.ico')])

Solution

  • This method should work:

    import sys
    from cx_Freeze import setup, Executable
    
    include_files = ['autorun.inf']
    
    base = None
    
    if sys.platform == "win32":
        base = "Win32GUI"
    
    exe = Executable(script='main.py', base = base, icon='icon.ico')
    
    
    setup(name = "Calculator",
            version = "0.1",
            description = "Simple Calculator",
            options = {'build_exe':{'include_files':include_files}},
            executables = [exe])