法一(auto-py-to-exe):Pyinstaller将yolov5的detect.py封装成detect.exe


pip install pyinstaller # 安装最新版本的pyinstaller指令

 # 在dist目录下只生成一个较大xxx.exe文件,所有依赖库全打包到exe中,打包后的exe可单独使用
pyinstaller -F xxx.py 

# 在dist目录下生成较小的exe文件,其他依赖库全都在dist文件夹下,打包后的exe不可单独使用
pyinstaller -D xxx.py  

# 选择exe图标机进行打包
pyinstaller -i icon.ico -F temp.py


# 其他pyinstaller 指令 查询P
pyinstaller -h

使用pyinstaller库与auto-py-to-exe可视化工具对pyqt程序打包输出exe文件。

一、准备

1.安装 pyinstaller

pip install pyinstaller
 

更新((初次安装忽略)):

pip install --upgrade pyinstaller
 

2.安装 auto-py-to-exe

  1. 安装

pip install auto-py-to-exe
 

打开工具

auto-py-to-exe.exe
 

  1. auto-py-to-exe 可视化转换工具:

二、打包

1.选择主程序路径,配置参数,点击生成

2.等待转换完成…

3.点击“打开输出目录”

扫描二维码关注公众号,回复: 17325246 查看本文章

4.进入main文件夹,找到main.exe,双击运行

三、YOLOv5 打包

YOLOv5打包exe,需要添加以下内容:

models.yolo
 

添加后,当前命令框自动生成转换代码,点击转换即可

四、打包过程问题解决

1.缺少dll依赖文件

  1. 报错:

OSError: [WinError 126] 找不到指定的模块。 Error loading “C:\Users\chen\output\main\torch\lib\caffe2_nvrtc.dll” or one of its dependencies.

  1. 解决:

按照报错提示路径找到对应的dll文件

将caffe2_nvrtc.dll文件拖动到Dependens软件中,查看缺少的dll文件

使用Everything查找缺失的文件

将其复制到exe工程的caffe2_nvrtc.dll同目录下

2.ImportError

  1. 报错:

ImportError: DLL load failed while importing QtWidgets: 找不到指定的程序。

  1. 解决:
  • 选择:“高级” - “–hidden-import” :

PyQt5.sip

3.其他

1.若提示缺乏文件夹,就将相应文件夹复制到工程的根目录中。
2.若提示缺乏pyc文件,就把带有该py文件的整个文件夹复制到工程的根目录中,并将对应的py文件后续改为pyc。

猜你喜欢

转载自blog.csdn.net/qq_53545309/article/details/135406591