我又来了,在经历过前面的一系列的操作,最终迎来了最后一步打包部署。
但似乎每一步走的都是那么艰难,回头看也就那样。
openvino官方说是不支持pyinstaller的打包,但是可以使用他们的管理工具。
下面就说一下我遇到的问题吧,不那么详细介绍每一步的流程,想知道每一步的具体流程可以去看一下我之前的文章。
按照之前的方式进行打包,只处理解决bug:(注:此次打包是打包为一个文件夹即(-D),是有这方面的需求,(-F)我想会比这更难)
环境说明:win10,openvino2021.4
1、缺少scipy
`Traceback (most recent call last):
File "predict_openvino_tcp.py", line 22, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "albumentations\__init__.py", line 5, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "albumentations\core\composition.py", line 8, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "albumentations\augmentations\__init__.py", line 5, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "albumentations\augmentations\transforms.py", line 13, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "skimage\measure\__init__.py", line 2, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "skimage\measure\_marching_cubes_lewiner.py", line 8, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "skimage\measure\_marching_cubes_classic.py", line 3, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "scipy\ndimage\__init__.py", line 153, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "scipy\ndimage\interpolation.py", line 37, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "scipy\special\__init__.py", line 643, in <module>
ImportError: DLL load failed: 找不到指定的模块。
[3600] Failed to execute script 'predict_openvino_tcp' due`
这个bug的原因是打包的时候scipy为打包进去就没找到相应的模块,还好自己的适用的是-D打包,不知道-F会整出来什么幺蛾子,不过-D之后可以使用一个工具变成整个exe,具体工具名忘记了。话说回来,最简单直接的方式就是代码运行的环境中找到scipy这个库的文件夹,将其复制至exe所在目录即可。
2、openvino库的打包缺少
①按照官方的管理工具进行处理
cd 至\openvino_2021\deployment_tools\tools\deployment_manager该目录
运行deployment_manager.py
在该界面下输入1回车,8回车,最后在回车(我使用的py3.7)按照自己的py版本进行选择。
输入g回车
提示完成。之后将产生的压缩文件夹中的文件复制至,exe所在环境中的openvino中。
运行exe文件出现错误:
Traceback (most recent call last):
File "predict_openvino_tcp.py", line 52, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "openvino\inference_engine\__init__.py", line 30, in <module>
File "ie_api.pyx", line 27, in init openvino.inference_engine.ie_api
ModuleNotFoundError: No module named 'openvino.inference_engine.constants'
[5452] Failed to execute script 'predict_openvino_tcp' due to unhandled exception!
提示缺少推理引擎的库,于是去安装目录找到推理引擎将该文件夹复制到相应目录,以及在代码运行的虚拟环境中找到openvino这个库的文件目录,或者去openvino安装目录去找,将其复制至此。
3、代码每次运行之前需要初始化环境(修改)
或者提示一下错误
Traceback (most recent call last):
File "predict_openvino_tcp.py", line 25, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "openvino\inference_engine\__init__.py", line 30, in <module>
from .ie_api import *
ImportError: DLL load failed: 找不到指定的模块。
[4408] Failed to execute script 'predict_openvino_tc
都可以进行一下操作
cur_path = os.getcwd().replace('\\', '/')
hdll_path = cur_path + '/openvino/deployment_tools/inference_engine/external/hddl/bin;'
tbb_path = cur_path + '/openvino/deployment_tools/inference_engine/external/tbb/bin;'
Debug_path = cur_path + '/openvino/deployment_tools/inference_engine/bin\intel64/Debug;'
Release_path = cur_path + '/openvino/deployment_tools/inference_engine/bin\intel64/Release;'
ngraph_path = cur_path + '/openvino/deployment_tools/ngraph/lib;'
model_optimizer_path = cur_path + '/openvino/deployment_tools/model_optimizer;'
os.environ['Path'] += hdll_path + tbb_path + Debug_path + Release_path + ngraph_path + model_optimizer_path
在impor之前加入这些代码就可以不用再去执行openvino/bin/setupvars.bat
脚本去初始化环境了。