Py学习  »  Python

python的Pyinstaller库的使用

初与久歌_4a05 • 3 年前 • 766 次点击  

Pyinstaller库的作用是将.py源代码转换成无需源代码的可执行文件,在Windows系统中会打包为.exe文件。Pyinstaller是python的第三方库,所以需要额外安装。

  • 安装方法

win+R弹出窗口
输入cmd打开命令行
输入命令
pip install pyinstaller

出现successfully installed的时候说明安装成功

Pyinstaller库的特别之处在于它并不是在python的IDLE环境使用,而是在 命令行环境 下使用。

常用参数 功能
-h 查看帮助
--clean 清理打包过程中的临时文件
-D, --onedir 默认值,生成dist文件夹
-F, --onefile 在dist文件夹中只生成独立的打包文件
-i <图标文件名.ico> 指定打包程序使用的图标(icon)文件
pyinstaller -F C:\Users\lenovo\coding\taoxin.py

59 INFO: PyInstaller: 3.6
59 INFO: Python: 3.7.4 (conda)
59 INFO: Platform: Windows-10-10.0.18362-SP0
64 INFO: wrote C:\Users\lenovo\taoxin.spec
70 INFO: UPX is not available.
72 INFO: Extending PYTHONPATH with paths
['C:\\Users\\lenovo\\coding', 'C:\\Users\\lenovo']
72 INFO: checking Analysis
163 INFO: checking PYZ
183 INFO: checking PKG
248 INFO: Building because C:\Users\lenovo\build\taoxin\taoxin.exe.manifest changed
248 INFO: Building PKG (CArchive) PKG-00.pkg
2689 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
2704 INFO: Bootloader e:\anaconda\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
2705 INFO: checking EXE
2713 INFO: Rebuilding EXE-00.toc because pkg is more recent
2713 INFO: Building EXE from EXE-00.toc
2714 INFO: Appending archive to EXE C:\Users\lenovo\dist\taoxin.exe
2722 INFO: Building EXE from EXE-00.toc completed successfully.

显示completed successfully。
之后在源程序对应的目录下会生成dist文件夹和 pycache 文件夹, pycache 文件夹可以安全删掉没有影响,dist文件夹打开之后就有对应的打包文件。


一般常用的参数还有-i,功能是可以把文件和对应的icon图标关联起来。

icon图标的图片在生活中不是很多见,在网上有在线生成icon图片的网站,可以很方便的把其他格式的图片转化成icon图片。链接如下 https://icon.wuruihong.com/icon?utm_source=ANm6Xyec#/ios

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/74261
 
766 次点击