Package Python code into a standalone EXE executable file under Windows environment

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.