The method of converting py file into exe executable file in Python

Time:2020-2-22

Background

Today, I have nothing to do. I wrote a little Python script program. When I showed it to my classmates, I found that I had to pull other people to look at my computer screen every time. I didn’t feel very happy. Then I thought that there must be operations on the Internet about converting Python scripts into executable files. I started to ask duniang about all kinds of information and found online ones There are too many materials. Some of them are old and suitable for the python 2. X series. In the current era of the popularity of Python 3, of course, we ignore them directly, but all kinds of methods are very messy. All kinds of tutorials are either complete or missing, and I have made trouble with them for a long time. Later, I found that a method was used by many people. In my own program, it was successfully packaged into execution files and tested in other people’s computers After that, I’ll take a note here. If there is something wrong, please point out.

 2、 Installation and configuration of pyinstaller

1. You can choose this website to open and download http://www.pyinstaller.org/downloads.html But I don’t recommend it. To be honest, I used the mobile broadband in the campus, 3.3m file. I downloaded it all afternoon but didn’t download it. If you look carefully, you will find that the download link of the attached Git is also below. I also used the GIT to download it.

2. Go to GitHub to download pyinstall package

3. After downloading, unzip it

4. Copy that folder to the script folder under your Python installation directory (attach a copy of my Python directory here, which may be helpful)

5. You also need to download a pywin32. You can download it here: https://sourceforge.net/projects/pywin32/files/pywin32/build% 20221 / choose your own version of Python parser, download it and double-click to install it. Next, next location~~

6. From the CMD command line, enter the scripts directory under the python 3 directory and execute: python pywin32_postinstall.py -install Command, as you can see, after the above step is completed, you will find this in the directory where you just unzipped the filepywin32_postinstall.pyfile

7. Enter in CMD command linepyinstaller-develop Directory (previously unzipped pyinstaller development folder), and then execute: python setup.py install

3、 After executing the above steps, the basic environment is configured, and you can make an EXE file. It only needs one line of command, which is very simple.

1. Copy your own py file topyinstaller-developDirectory (previously Unzippedpyinstaller-developFolder).

2. Enter the directory at the CMD command line and execute the command: python pyinstaller.py -F Your file name.py

3. Wait a moment, a successful EXE file will be finished. Will be inpyinstaller-developIn the directory, there is a folder named after your script file. Click in, and the EXE file will be under the dist folder.

4. Production completed!

Four, summary

I don’t think it’s difficult. According to this practice, the problems are not big. I hope to see this tutorial and succeed. But there is a small disadvantage of this thing. Even if the script file is very small, tens of KB, I feel that the generated execution file can be large. If I learn other methods to convert py file to EXE file in my later study, I will definitely record and share it under the blog for the first time. Thank you.