pyinstaller使用记录
pyinstaller使用记录
需求
为了在没有 python 环境的电脑上运行 python 脚本,使用 pyinstaller 打包脚本为 exe
打包命令
pyinstaller -F .\main.py -n test
- -F 打包为一个 exe 文件
- -n 打包后文件夹名称
打包静态文件
有两种方式:
打包静态文件时,需要注意不能使用-F命令打包为一个 exe 文件,需要使用-D打包为一个文件夹
1. 命令指定需要一同打包的静态文件
参考官方文档
pyinstaller -D .\main.py -n test --data-file 'src/README.txt;.'
'src/README.txt;.'中 windows 使用;连接, unix 使用:
2. 修改spec文件配置
参考官方文档
- 先使用
pyinstaller -F .\main.py -n test打包,会生成一个test.spec文件; - 修改生成的
test.spec文件中配置, 修改datas为datas=[('原静态文件或文件夹', '目标文件或文件夹')]; - 使用命令
pyinstaller test.spec

浙公网安备 33010602011771号