pyinstaller ___ python Program packaging exe
Open in an appropriate folder Directory cmd
( Or open cmd Then go to an appropriate file directory )
Create a venv Virtual environment for
virtualenv venv
Create good after , Activate it ~
venv\Scripts\activate
① Will be ready to pack py Program files , Pull to this directory .
② besides , Prepare an icon file (ico Picture file )
Note that it cannot be a simple picture , It needs to be integrated under different resolutions ico file , To ensure normal display under different conditions . Otherwise, packaging exceptions may occur .
This needs to be implemented with related tools , Such as , It is recommended to use Greenfish Icon Editor Pro, The operation is very simple , Don't get stuck here .
( The original icon image can be displayed by itself ppt Top production , That's what I did . After the painting is finished, you can take it to make it ico file )
③ Install related libraries
That is, use the commonly used pip install Command to complete .
except py Files need to be outside the library , It is also necessary to install the necessary pyinstaller library :
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
After they are all installed , To view :
pip list
Common packaging commands are as follows :
Pyinstaller -F -w -i icon.ico demo.py
among ,
F Indicates that the program is all packaged together , Only one .exe file , The files generated by this method are highly integrated , But it's slow ;
If don't write -F, A series of .dll file , There are many files in such a program , But it runs faster .
w It means to pack up exe The program does not pop up when it is running cmd The interface of .
i Represents icon parameters .
After packing , A... Is generated in this directory build Folders and one dist Folder . Generated exe The document is in the dist In the folder , With primordial py The same name of the file .
Generated build The function of a folder is equivalent to PyInstaller Working space for ,PyInstaller The files and logs related to running are in this folder , After packaging, you can delete it directly .
If py Files need to be loaded and used in the permitting process .
Such as read_excel() Read excel file ,opencv Loading Cascading Classifier files, etc , You can write py Code , Use the default location ( Current directory );
After packaging , Manually move attached files to dist Under the folder , To that of the exe The file is the same as the directory .
If this point is ignored, an error will be reported .