程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

pyinstaller ___ Python program packaging and exe implementation

編輯:Python

pyinstaller ___ python Program packaging exe

List of articles

  • 1. Create a virtual environment and activate
  • 2. Resources to prepare
  • 3. pack
  • 4. About the attached documents

1. Create a virtual environment and activate

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

2. Resources to prepare

① 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

3. pack

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 .


4. About the attached documents

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 .



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved