1、 install pip install pyinstaller( Installation address )
2、 Switch to the project path that needs to be packaged cd D:\task\pyqt5
3、 Run the command pyinstaller -F main.py (xxx.py Packaged files )
4、 After successful packaging, the project is added dist file , Enter and click to run the packaged exe Program
Pyinstaller Common parameter usage :
Recommend an icon to get the address , Inside ico Quite a lot :easyicon
Download my favorite ico after , use -i+ico Path to replace the default ico, Run rebuild as Administrator exe Tools ,
The order is pyinstaller -i ico route -w xxxx.py
Lin Mou utilization pyqt Write a graphic interface for emotional annotation of pictures GUI, But the number of pictures to be marked is too large , It can only be marked multiple times by time period , However, the number of personnel completing each marking is random , At the next dimension , The new index given should be the last callout end index +1. So you need to pass the index value to exe File corresponding py file , Realize dynamic following .
1、main.py The following code should appear in the file :
self.index = int(sys.argv[1])
2、 Open the command prompt window cmd, Switch to main.exe Location path , such as cd D:task\1\, Reenter command main.exe 0 #0 Represents emotional annotation from the first picture
3、 The next time you need to pass parameters , repeat 2 The operation of , Reenter command main.exe 456 #456 From the first 456 Picture begins with
Why argv[1]?
sys.argv A variable is a that contains command line arguments character string list , That is, use the parameters passed to the program from the command line . Example :cmd perform python using_sys.py we are arguments
The output is as follows :
#encoding=utf-8
import sys
a=sys.argv[0]
b=sys.argv[1]
c=sys.argv[2]
c=sys.argv[3]
print("filename:",a)
print("param1:",b)
print("param2:",c)
print("param3:",d)
Output :
('filename:', 'using_sys.py')
('param1:', 'we')
('param2:', 'are')
('param3:', 'arguments')
among ,sys.argv[0] The default indicates the file path of the code itself , Therefore, manually passed parameters need to be from sys.argv[1] Start
Try not to use import, can from…import… Just try to use this , Because if it is import Words , When packing , Will pack the whole package to exe Inside , Meaningless increase exe The size of the tool
use Pyinstaller pack Python Program + Solve the problem that the packaging result is too large