Although our program was already written, it was dependent on the Python environment. \

How can we convert Python files into exe executable files? I took the opportunity to learn about the PyInstaller package module. \

The command used is a single line: \

1pyinstaller -F tm_01_birthday.py
Copy the code

Even though the command was a single line, I went through a lot of pitfalls from executing it to actually packaging it into a 26.9 Megabyte executable. \


Pit 1 recursion is too deep

I typed the above single line command directly in the directory where the py file was located, and soon got an error.

According to the CSDN blog, it looks as if a library is playing too hard with recursive traversal on its own, exceeding Python’s stack height limit.

Solutions are as follows:

1) pyinstaller -F tm_01_birthday.py

This step will definitely fail with the above error, but will produce a tM_01_birthday.spec file

2) Add two lines to the xxx.spec file (added to the second line of the original file):

1import sys
2sys.setrecursionlimit(5000)
Copy the code

3) pyinstaller tm_01_birthday.spec

So far, I successfully packaged the EXE file!

So, you think that’s it?

Don’t.

Look at the size of this file! 303 m!


Pit 2 file is too large

Why does this happen? \

Because the Anaconda I used, together with some unnecessary files, were packed together, resulting in a large file. \

I searched again, and there were two possible solutions.

1) Use the Pipenv module to create a virtual environment under the file directory and package files in the virtual environment.

I tried, but it was 303M! Don’t know why!

But I didn’t give up!

2) Use a pure Python environment

I had a spare computer on which I uninstalled Anaconda and installed a pure Python.

My program requires two third-party modules: Pandas and WXpy.

Install it first with PIP and then execute the one-line command with PyInstaller.

Ok at last!

File size 26.9m \


Pit 3 External data \

Once packaged, an EXE file is generated in the dist folder, but nothing happens when I run it.

Why is that?

I did some more searching and found it was the data.

When my program loads excel, it uses a relative path. So, the program is waiting for my Excel spreadsheet!

I copied the Excel spreadsheet into the dist folder and opened the program again!


This time it really worked! \

It started to prompt me to log in the web version of wechat!

The list of students is then displayed in the pane along with a successful message delivery. Finally, I saw the message sent in the mobile phone wechat!# Copy the following code to open baidu web disk on the mobile end!
Package file source codeLink: HTTPS://pan.baidu.com/s/1y3p-hqRbxzOSztP7jEjQEwExtract code: wshc-end -Copy the code