常用打包工具:
py2exe
Cx_Freeze
PyInstaller
本文使用PyInstaller
作用:
无需安装Python解释器或任何模块即可运行打包的
应用程序;将Python应用程序及其所有依赖项捆绑到一个包中。
安装: pip install pyinstaller
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
步骤
1、把相关py文件放到一个文件夹中,如PyTool文件夹
2、Terminal进入 D:\Python_study\myPyQt\PyTool
3、录入pyinstaller 主文件.py
dist会生成exe
弊端依赖项太多文件
改进的方式
pyinstaller [opts] [要打包的程序.py]
可选的opts有:
-F, –onefile 打包成一个exe文件。
-D, –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)。
-c, –console, –nowindowed 使用控制台,无界面(默认)
-w, –windowed, –noconsole 使用窗口,无控制台
pyinstaller -F pydes_tool.py
-c使用控制台
pyinstaller -F -c pydes_tool.py
-w使用窗口
pyinstaller -F -w pydes_tool.py
更改图标:
如果需要给exe程序带上图标,可以网上自行下载.ico后缀名的图片,然后使用命名
pyinstaller -F -i pydes_tool.ico -w pydes_tool.py