1

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')])
laxer
  • 720
  • 11
  • 41

1 Answers1

2

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])
Vagif
  • 224
  • 1
  • 3
  • 17
  • That worked! Thank you! Can you explain to me why that worked and my second attempt did not? – laxer Apr 12 '17 at 21:06
  • @laxer you only had a tiny problem. On line `executables=[Executable("main.py", base = base, icon = 'icon.ico')])`, you must put in `script = 'main.py'` which you forgot – Vagif Apr 13 '17 at 07:08
  • @ Vagif I just thought that would produce an error, but thank you for the answer and the description. That was very helpful!! – laxer Apr 13 '17 at 14:39