Hello everyone, I am a rookie.
In order to send Python programs to colleagues and friends who do not understand code and do not have Python installed, the best way is to package the Python program into an exe executable file and then send it to them.
I have packaged several times before, and the operation is not difficult, but I cannot remember the packaging commands. I need to check the commands again every time I package. Therefore, this article records the packaging process. When you need to package, you can directly copy and paste it and complete it quickly without using your brain.
pip install pyinstaller
The icon uses an ico icon of 48*48 size (can be adjusted as needed) It is more appropriate. You can first prepare the image to be used as an icon, find an online ico icon conversion website, convert it into an ico icon, and download it for use.
There are many tools for converting ico icons online. Just search online to find one that works. Public accounts cannot put external links. When you get the tools for this article below, you can get the link to the tool I used.
Create a folder and put the Python program that needs to be packaged and its dependent files and icons into this folder.
Open the command line in the folder and execute the packaging command.
pyinstaller -F -w -i *.ico -n xxx *.py
*.ico is the name of the icon file prepared earlier, *.py is the name of the Python program that needs to be packaged, and xxx after the -n parameter specifies the exe file name of the packaging result.
This article takes the code for drawing a little tiger at the beginning of the year as an example. Copy the code draw_tiger.py and the icon tiger.ico to the newly created folder, open the command line and execute the packaging command:
pyinstaller - F -w -i tiger.ico -n tiger draw_tiger.py
Wait for the command execution to complete, and the packaging is completed.
After the packaging is completed, three folders and a file ending with .spec will be generated in the current folder. Double-click to open the .exe file in the dist directory. You can run the program (if the Python program has dependent files and they are not automatically placed in the dist directory, you must copy the dependent files into it first). You can also create a desktop shortcut for the .exe file, and then open and run it directly on the desktop, which is more convenient.
I also uploaded the .exe file packaged this time to Baidu Netdisk, which can be obtained by replying "Tiger Tiger Shengwei" in the background of the official account.
This .exe file can be sent to colleagues and friends, and can be run directly on their computers.
If there are dependent files such as called files or pictures in the Python program, just put them in the same folder as the .exe file and send them to colleagues and friends.
Packaging parameters
If you need to view all parameters of pyinstaller, you can execute pyinstaller --help on the command line to view it.
pyinstaller --help
Packaging results
The above is an introduction to packaging Python programs into exe. Bookmark this article to facilitate future copying. Welcome to like, read and share.
The above is the detailed content of Learn this trick and it really works! Copy and paste to quickly package Python programs into exe!. For more information, please follow other related articles on the PHP Chinese website!