How to package a python file as an. exe executable file under Windows

Source: Internet
Author: User

When using Python for development, you will occasionally write some gadgets to assist your own work, but because development depends on the environment, most of them can only be run on their own computers, the other computer can not be run. This seems very inconvenient, not in line with our original intention, then there is no way we can write a good program, you can directly run under a variety of Windows?

The answer is: Yes, that's what windows can think of (. exe). Yes, it's just a matter of wrapping up Python-written code into executable EXE files that run directly on the system.

Here's how to do it, specifically as follows:

Installing the Pyinstaller Library

Before implementing EXE, we need to install a third-party Pyinstaller dependent Library to package the py file into an executable. exe file through this library.

Install using the PIP tool under Windows:

1pip Install Pyinstaller # PIP tool

Or

3PIP3 Install Pyinstaller # PIP3 Tool

Install under Linux:

1sudo apt-get Install Pyinstaller # Ubuntu or Linux ... System

2

3yum Install Pyinstaller # CentOS System

Packaging Demo

After installing the Pyinstaller library, you can use the PYINSTALLER–HELP directive to get instructions for using the library, which describes the simplest way to package:

1) Create a test.py file

2) package The test.py file as an (. exe) file with the following directives:

1pyinstaller-f test.py

After the execution of the program, 4 files are generated in the current directory: Dist, __pycache__, build, Test.spec, which can execute files stored in the Dist folder.

Simply package the 3 files in one folder and run them directly on the other Windows platform. Is it simple and convenient .....

How to package a python file as an. exe executable file under Windows

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.