Python CX-Freeze

Python - CX_Freeze

Used to create standalone executables from Python scripts

pip install cx_Freeze

It requires setup file (python file) setup.py should at least contains

from cx_freeze import setup, Executable

setup( name = "foo",

version = "1.1",

description = "Description of the app here.",

executables = [Executable("foo.py")]

)


Example code

guifoo.py

from Tkinter import *

class Window(Frame):

def __init__(self, master=None):

Frame.__init__(self, master)

self.master = master

self.init_window()

#Creation of init_window

def init_window(self):

# changing the title of our master widget

self.master.title("GUI")

# allowing the widget to take the full space of the root window

self.pack(fill=BOTH, expand=1)

# creating a button instance

quitButton = Button(self, text="Am Foo Exit Me")

# placing the button on my window

quitButton.place(x=0, y=0)

root = Tk()

#size of the window

root.geometry("400x300")

app = Window(root)

root.mainloop()

Setup.py

import sys

from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.

build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a

# console application).

base = None

PyfileName = "guifoo.py"

AppName ="GUI Foo"

if sys.platform == "win32":

base = "Win32GUI"

setup( name = AppName,

version = "0.1",

description = "My GUI application!",

options = {"build_exe": build_exe_options},

executables = [Executable(Py_fileName, base=base)])

To make exe, Place files in code path and using cmd run following command

>>python setup.py build_exe