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文件配置

参考官方文档

  1. 先使用pyinstaller -F .\main.py -n test打包,会生成一个test.spec文件;
  2. 修改生成的test.spec文件中配置, 修改datasdatas=[('原静态文件或文件夹', '目标文件或文件夹')]
  3. 使用命令pyinstaller test.spec
posted @ 2021-09-05 20:03  守望人间  阅读(76)  评论(0)    收藏  举报