Cx_freeze is a tool used to encapsulate Python scripts as executable programs, supporting the latest version of Python3.2. The resulting execution file is cross-platform and runs without the need to install Python on the system. At present, similar functions of the tool has Py2exe and Pyinstaller, which seems to py2exe popularity is the highest, but a long time no update, as for the quality of packaging not to do evaluation, after all, radish vegetables each their own; Pyinstaller not very understanding, it is said that the process is very complex; As for Cx_ Freeze's powerful features and ease of use, I highly recommend.
The detailed installation steps are as follows:
1. Installation Cx_freeze (official: http://cx-freeze.sourceforge.net)
2. Check if the Cx_freeze installation is successful (Windows OS)
3. Prepare a simple hello.py applet
hello.py
4. Package Python scripts into executables (two methods)
cmd> cxfreeze hello.py--target-dir Dist
- Use profile (Personal recommendation = + Write Once, everywhere available?):
cmd> python setup.py build
setup.py Configuration Program:
1 #
2 # File name: setup.py
3 # Function Description: Cx_freeze package Python script configuration file
4 #
5 # Renzo Date: 2012/01/01
6 #
7 # Copyright: Can be used, spread, but please keep the source, if you need to change, please inform the author.
8 #
9
From Cx_freeze import Setup, executable
11
12
13 # First deal with internal variables such as Path,includes,excludes,packages
Base = "Win32gui"
Path = []
includes = []
excludes = [' _gtkagg ', ' _tkagg ', ' bsddb ', ' curses ', ' email ', ' pywin.debugger ',
' Pywin.debugger.dbgcon ', ' pywin.dialogs ', ' tcl ', ' tkconstants ',
[Tkinter]
packages = []
21st
22
23 # Here you can write customized pre-processing code for encapsulation. Example: processing of data files
24
25
26
27 # Configuring the encapsulated parameters
Gui2exe_target_main = executable (
Path = path,
Base = Base,
31
32 # Generate the main file of the executable file
A script = "simple.py",
34
35 # Generate executable file and some dependent files directory
TargetDir = r "Dist",
37 # Executable file name
TargetName = "Simple.exe",
39 # executable file ico icon
+ icon = "Simple.ico",
41
Includes = includes,
excludes = excludes,
Packages = packages,
45
46 # If you need to compress the bytecode of the module
Compress = True,
48
49 # Whether to copy dependent files to the target directory
Copydependentfiles = True,
51
52 # Whether to attach script module to execute file
Appendscripttoexe = True,
54 # Whether to add script modules to shared libraries
Appendscripttolibrary = False,
56
57 # Set the path and name of the shortcut
Shortcutdir = "",
Shortcutname = ""
60)
61
62
63 # Set the description of the package during installation
Setup (
The name = "Simple",
Version = "0.1",
Description = "My First python program",
68
Author = "Renzo",
Author_email = "[email protected]",
71
url = "Wwww.cnblogs.com/renzo",
73
74 # Generated executable file
executables = [Gui2exe_target_main]
76)
77
78
79 # Here you can write customized encapsulation post-processing code. Example: Cleanup of temporary data, release of data packets, etc.
80
81
82
83 # To this, the entire setup script has been completed.
5. Generated executable file (Xxxx.exe)
6. Implementation results
Congratulations, you can pack the entire target directory and publish it.
Encapsulates a python script into an EXE executable file