[Python] cx_freeze not finding icon

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am using cx_freeze to create an exe file. The cx_freeze setup file includes reference to the icon (HPS.ico) and appears to successfully run and creates the exe file.

    from cx_Freeze import setup, Executable

    # Dependencies are automatically detected, but it might need
    # fine tuning.
    build_options = {'packages': ["seaborn","matplotlib","rasterio", "tkinter"],
    'excludes': []}

    base = 'gui'

    executables = [
    Executable('HPS_model.py', base=base, target_name = 'HPS_Model',
    icon="HPS.ico")
    ]

    setup(name='HPS Model',
    version = '1',
    description = 'HPS Model',
    options = {'build_exe': build_options},
    executables = executables)


    The executable file is present with the HPS icon attached in the build directory. When I run the exe file I get the following popup error:


    -tkinter.TclError:bitmap C:\Users\rp\Documents\HPS\Final\build\exe. win-amd64-3.12\lib\library.zip\HPS.ico not defined
    ​

    Oddly enough when the popup error comes up the HPS icon also appears on the task bar below. There is no HPS.ico in the library zip file. After online searches for icon problems with cx_freeze I made sure that (1) I am not using python downloaded from the Microsoft store, (2) I have used pip to uninstall and re-install the latest version of cx_freeze, and (3) I have also imported png file to online ico converter to create ico to ensure its the right format. Any suggestions would be greatly appreciated. Thanks.

    Continue reading...

Compartilhe esta Página