1.安装
pip install pyinstaller
2.打包
pyinstaller --onefile main.py
--onefile 表示将所有内容打包成一个 .exe 文件。
打包完成后,会在 dist/ 目录下生成 main.exe。
pyinstaller --onefile --noconfirm --windowed --icon=app.ico --name=EXE名称 main.py
参数 作用
--onefile 所有依赖打包成一个 exe 文件
--noconfirm 自动覆盖输出目录,不提示
--windowed 不显示命令行窗口(适合 GUI 程序)
--icon=app.ico 设置 exe 图标(可选)
--name=xxx 设置输出的 exe 名称
就一行命令
pyinstaller --onefile --name=生成的EXE名称 待编译的python文件.py