Package your own python code into an exe executable file

       Packaging your own python files into exe files can reduce the program's dependence on the environment, and make your code run perfectly on windows systems that do not have a python environment. Today we will learn about the python file packaging tool pyinstaller.

1. Install pyinstaller.

(1) Open the cmd run window and enter:

pip install pyinstaller 

(2) Go to the official website http://www.pyinstaller.org to download the installation package corresponding to your python version.

2. Use.

(1) Package the code directly.

pyinstaller -F test.py

Specify the code path after -F.
(2) Make a small personalized icon package code.

pyinstaller -i test.ico -F test.py
  • Specify the icon image path after the -i parameter, the image format must be .ico, and specify the code path after -F. I recommend a website http://www.faviconico.org/ to convert other image formats into .ico format.

(3) Let the script not pop up the command window, provided that the GUI library is used.

pyinstaller -F -w  -i test.ico test.py

PS: Please make sure your code can run smoothly in your own environment before packaging.

3. Examples.

(1) Put the icon and code in the same folder.
Insert picture description here
(2) cmd enters this folder to start packaging, as shown in the figure, the packaging is completed normally.
Insert picture description here
(3) Three folders will be generated under the corresponding folder, exe files will be generated in the folder dist, and the remaining folders can be deleted.

Guess you like

Origin blog.csdn.net/sun124608666/article/details/111149021