Are you interested in the actual application of py2exe packaging Python scripts? Do you know how to package Python scripts in py2exe? These two questions will be mentioned in the following articles. I hope you will have a better understanding of them after browsing.
I. Introduction
Py2exe is an executable program (*. in this way, you can run this executable program on windows without installing python. Py2exe has been used to create wxPython, Tkinter, Pmw, PyGTK, pygame, win32com client and server, and other independent programs. Py2exe is released under the open source license.
- Application solution of Python scripts in other language Environments
- Introduction to the advantages of python script in practical application
- The five advantages of the vim compiler in Python scripts
- Code about LineCount. py in the Python script file
- Python scripts and C ++ programs call each other
Ii. Install py2exe
Download and run the installer of the py2exe version corresponding to your installed Python. This will install py2exe and the corresponding example; these examples are installed in the lib \ site-packages \ py2exe \ samples Directory.
Iii. Usage of py2exe
If you have a file named myscript. you want to convert the python script of py to an executable program running on windows and run it on a windows system without python installed, first, you should write a setup script for the release program, such as mysetup. py, insert the statement import py2exe before the setup function.
An example of mysetup. py is as follows:
- # mysetup.py
- from distutils.core import setup
- import py2exe
- setup(console=["myscript.py"])
Run mysetup. py as follows:
- python mysetup.py py2exe
Upload these files.
If your myscript. if the compiled C extension module is used in The py script, these modules will be copied to sub-directories. Similarly, all dll files are required at runtime, besides system dll files.
The files in the dist subdirectory contain what is necessary for your program. You should publish all the content in this subdirectory together.
By default, py2exe creates the following necessary files in the dist directory:
1. One or more exe files.
2. python ##. dll.
3. Several. pyd files, which are compiled extensions and required by the exe files. With other. dll files, these. dll files are required by. pyd.
4. A library.zip file that contains compiled python modules such as. pyc or. pyo
Mysetup.pycreated a console myscript.exe program. If you want to create a program in the graphic user field, you only need to set mysetup. console = ["myscript. replace py "] with windows = [" myscript. py. Py2exe can create multiple exe files at a time. You need to pass the 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 command line labels of the py2exe command.
The above is an introduction to how to use py2exe to package the Python script. I hope you will get something.