1. 安装打包程序:
pip install pyinstaller
2. 创建一个文件夹并将python文件放在其中,再输入打包命令
3. 打包命令:
pyinstaller -F -w -i 图标.ico 文件名.py
使用方法:
-F:打包 Python 程序为单个可执行文件
-D:打包 Python 程序为一个文件夹
-i:生成图标,只适用于 Windows 平台
-n:指定打包后生成文件的名称
-w:禁止命令行弹出
注意:
-i 参数后必须接 .ico 结尾的图标文件
-D 或 -F 后必须接 python 程序的入库程序,常见情况为 main.py,对应依赖比较多的程序,建议使用 -D, -F 更适合单文件的 py 脚本
4.报错
解决方法:
打包时报错:The 'typing' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please `pip uninstall typing` then try again.,
报错原因:typing包版本与Pyinstaller不兼容
解决方法:直接使用命令:pip uninstall typing 卸载即可
打包时报错ValueError:read length must be non–negative or -1
报错原因:可能是图标ico文件太大了
解决方法:选择一个图片在ico网站制作
ico制作:https://www.ico51.cn/