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