Sometimes because of business trip, suddenly urgent need to deal with a batch of data. While the written script is stored in the cloud, the compiled environment needs to be re-built, and the modules need to be reloaded, from start to finish, and at a considerable cost of time.
Is there a way to make a. py file as click-to-run as an executable file?
Py2exe Module
Py2exe, as the name implies, translates. py files into executable. exe files so that you can get rid of the limitations of the build environment and preloaded modules and run in any Windows environment.
First, install the Py2exe
Through the PIP installation module, the download completes automatically after the installation succeeds, then can confidently use the Py2exe boldly.
ii. target. py file
1 # target. py file, which is the file we need to convert to. exe, named test.py 2 Print ('Hello world! ')
Iii. Package the. py file into a standalone executable. exe file
We need to write a separate. py file separately, and the interface points to the target. py file.
1 # convert the. py file to convert the target. py file to a. py file that can be executed separately, named setup.py 2 from Import Setup 3 Import Py2exe 4 5 Setup (console=['test.py')
After completing the above steps, we now have two. py files, each of which we need to "convert" the target. py file, and the. py file with the "Convert" feature
Run the following code in CMD:
1 python setup.py py2exe
In the setup.py file sibling folder There will be a dict folder, which is the folder where the. exe file can be executed independently after conversion.
Where the Test.exe file is the file that we can execute after conversion, all files in the Dict file are the necessary files to ensure that the. exe can run independently.
-Python**.dll:python Master Linkage Library, * * for version number
-. PYD: compiled. py file
-Library.zip: The compressed package contains the compiled module file in the form of. PYc
Run successfully!
Package Python code into a standalone EXE executable file under Windows environment