If you use Python Wrote a very good gadget , Then others like to use , Do you feel a sense of accomplishment ? I always hope that more people can use it ?
But I don't understand Python People who , If you send it directly python file , It is still difficult to run , If you can put the python The file is packaged as an executable exe, stay windows Double click on the system to run , That will greatly facilitate people to use .
This article introduces how to put Python GUI The program is packaged as an executable file exe, Can be in windows Double click on the system for easy use .
Life is too short , I use Python,Python Why is it so popular , Because its development is fast and convenient , Write the script , Write gadget , Develop web site , Data analysis , Artificial intelligence makes python radiant , And it's all due to python Rich library .
The simple understanding is , If you want to build a car , There is no need to start with the wheel , All you need to do is find all the parts to build a car , Put it together , A car becomes .
Python this is it , Rich third-party library , Let you in the development process , You don't have to start with making wheels every time , Instead, take the wheels directly and assemble them , Quickly develop the model you need to .
If we want to put python The file is packaged as exe Executable file , Is there such a library ? The answer is yes .
We use third-party libraries pyinstaller Go pack python file .
Let's introduce how to use pyinstaller pack Python file ?
1. install pyinstaller Third party Library
pip install pyinstaller
2. Execute package command
pyinstaller yourprogram.py
what , It's that simple ?
Yes , You read that right , Just two steps , What you need exe The file is generated , Put it in your yourprogram.py The file is the same as dist Folder , You can happily send it to others to show off , Ha ha ha .
Yes, of course , If you still need something customized , For example, I want to pack one GUI Program , The default icon is too ugly , I want to change a more beautiful icon and so on , We only need to add some parameters to complete , Let's pack it up GUI Program, for example , Briefly introduce the following parameters
Let's first look at the commands I finally packaged
pyinstaller -F -w -i 16.ico -n active get_register_code.py
Let me introduce the parameters used
-F
Specifies that only one... Will be generated after packaging exe File format
-w
No display windows cmd window ( Because we are GUI Program , There is no need to show cmd window , Namely windows That ugly black cmd window )
-i
After replacement and packaging exe Display icon of the file , Followed by the icon file you need to replace
-n
Specify packing as exe File name of , Followed by what you want exe name
this is it , From then on, I can write you python The program is packaged as exe Send it to Xiaobai smelly to show off , Get a sense of accomplishment , You can also continue to fool your goddess , Ha .
Expand :
pyinstaller There are many other parameters that can achieve different effects , When you need it, you just need to check the document and it will be clear at a glance .