First, Introduction
Py2exe is a tool for converting a Python script into a standalone executable program (*.exe) on Windows so that you can run the executable program on a Windows system without having to install Python. Py2exe has been used to create wxpython,tkinter,pmw,pygtk,pygame,win32com client and server, and other standalone programs. The Py2exe is released under an open source license.
- Application scenarios for Python scripts in other locales
- Introduction to the advantages of Python scripting language in practical applications
- The five great advantages of the Vim compiler in a Python script are related
- The relevant code for the Python script file linecount.py
- The actual operation of the Python script and the C + + program calling each other
Second, installation Py2exe
Download and run the Py2exe version of the installer that corresponds to the Python you installed, which installs Py2exe and the corresponding example, which are installed in the Lib\site-packages\py2exe\samples directory.
Third, the use of Py2exe
If you have a Python script named myscript.py, you want to convert it to an executable program running on Windows and run on a Windows system that doesn't have Python installed, So first you should write a setup script for the release program such as Mysetup.py, which inserts the statement import Py2exe before the setup function.
The mysetup.py example is as follows:
# mysetup.py from Import Setup Import py2exe Setup (console=["myscript.py"
Then run the mysetup.py as follows:
Python mysetup.py Py2exe
When the above command executes, it will produce a subdirectory named Dist that contains the Myscript.exe,python24.dll,library.zip files.
If your myscript.py script uses compiled C extensions, the modules are also copied in the subdirectory, and all DLL files are required at run time, in addition to the system's DLL files.
The files in the Dist subdirectory contain what is necessary for your program, and you should publish all the content in this subdirectory.
By default, Py2exe creates the following required files under Directory dist:
1, one or more EXE files.
2, Python##.dll.
3. Several. pyd files, which are compiled extensions that are required by the EXE file, plus other. dll files that are required by the. PYD.
4. A library.zip file that contains compiled pure Python modules such as. PYc or. pyo
The above mysetup.py creates a console Myscript.exe program, if you want to create a graphical user interface program, then you just need to mysetup.py console=["myscript.py" replaced with windows=[" myscript.py "] can either. Py2exe can create multiple EXE files at once, you need to pass a list of these Python script files to the console or Windows keyword parameters.
This is useful if you have several associated scripts. Run the following command to display all the command line tokens for the Py2exe command.
Executable program for converting to Windows with a Python script