当前位置: 代码迷 >> 综合 >> 使用 pyinstaller 打包Python脚本为可执行程序
  详细解决方案

使用 pyinstaller 打包Python脚本为可执行程序

热度:12   发布时间:2023-12-15 04:46:55.0

文章目录

  • 1. 安装 pyinstaller
  • 2. 终端执行打包

使用 ./test /Users/xxx/imgs/selfie5.jpg,成果:

(tensorflow) Robin-macbook-pro:dist robin$ ./test /Users/xxx/imgs/selfie5.jpg输入图像的图像大小:(height, width)=(3088, 2316)处理后的图像大小:(height, width)=(1280, 960)

话不多说直接上步骤:

1. 安装 pyinstaller

  • pip install pyinstaller

2. 终端执行打包

  • cd xxx(脚本所在位置)
  • pyinstaller -F xxx.py(我的是 test.py)
    在./dist文件夹下即可找到可执行程序
    ![在这里插入图片描述](https://img-blog.csdnimg.cn/6597f69ed12648c5b79fe14860348fc2.png
    #3. 执行可执行程序
  • cd xxx(可执行程序所在位置)
  • test 参数即可(我的脚本需要输入参数)

几点 tips:

  1. Mac 上生成的可执行程序只能在其它 Mac上运行
  2. 也可以使用pyinstaller -D等参数(生成的是一个文件夹,-F 生成的是单个文件)