1、安装pyinstaller
pip install pyinstaller
安装后,运行pyinstaller.exe
命令出现使用方法,表示安装成功了。
参数介绍
选项 | 说明 |
---|---|
-F | 打包一个exe文件 |
-D | 打包多个文件,在dist中生成很多依赖文件 |
-d | 产生debug版本的可执行文件 |
-w | 程序启动不打开命令行 |
2、打包.exe
- 终端运行:
pyinstaller.exe -F -w main.py
。其中main.py是你的主程序入口,此时会生成main.spec文件。 - 终端运行:
pyinstaller.exe -F -w main.spec
。dist目录下出现exe文件,这个mian.exe文件就是我们需要的可执行程序。 - 如果下次需要编译,直接
步骤2
即可,步骤1
只是生成.spec
文件。
3、编写自动化编译bat脚本
@echo off
set s=.spec
set /p py=input main_file name:
call :print %py%
goto :eof
:print
set py_name=%~n1
set spec=%py_name%%s%
if not exist %spec% (
@echo --------------------create file.spec--------------------------------
pyinstaller.exe -F -w %py%
)
@echo ====================create file.exe================================
pyinstaller.exe -F -w %spec%
@echo compile is OK!
输入格式是你的主程序,如main.py
。