打包准备
1. 安装pyinstaller
conda create -n opinstall python=3.7 -y
conda activate opinstall
pip install openvino
pip install pyinstaller
2. 将openvino文件夹复制到代码同级目录下
D:\ProgramData\anaconda3\envs\openvino_install\Lib\site-packages\openvino 拷贝至 F:\openvino_install
3. 修改配置
# 将运行库路径修改为同级目录下的openvino目录
打开openvino/inference_engine/_init_.py
》修改:openvino_libs = [os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs")] 为:openvino_libs = [os.path.join(os.getcwd(),'openvino\\libs') ]
》增加python版本小于等于3.8环境配置,否则报错DLL load failed while importing ie_api: 找不到指定的模块。
if (3, 8) <= sys.version_info:
os.add_dll_directory(os.path.abspath(lib_path))
os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"]
else:
os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"]
》增加:
from .ie_api import *
from .constants import *
# -*- coding: utf-8 -*- # Copyright (C) 2018-2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 import os import sys if sys.platform == 'win32': # Installer, yum, pip installs openvino dlls to the different directories # and those paths need to be visible to the openvino modules # # If you're using a custom installation of openvino, # add the location of openvino dlls to your system PATH. # # looking for the libs in the pip installation path by default. openvino_libs = [os.path.join(os.getcwd(),'openvino\\libs') ] # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. openvino_libs_installer = os.getenv('OPENVINO_LIB_PATHS') if openvino_libs_installer: openvino_libs.extend(openvino_libs_installer.split(';')) for lib in openvino_libs: lib_path = os.path.join(os.path.dirname(__file__), lib) if os.path.isdir(lib_path): # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. if (3, 8) <= sys.version_info: os.add_dll_directory(os.path.abspath(lib_path)) os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] else: os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] from .ie_api import * from .constants import * __all__ = ['IENetwork', 'TensorDesc', 'IECore', 'Blob', 'PreProcessInfo', 'get_version'] __version__ = get_version() # type: ignore
开始打包
G:\pyopenvino>conda activate opinstall
(opinstall) G:\pyopenvino>pyinstaller --onefile --hidden-import pkgutil app.py
1. 启动之前初始化
G:\pyopenvino\dist>conda activate openvino_test
(openvino_test) G:\pyopenvino\dist>cd C:\Program Files (x86)\Intel\openvino_2021.4.752\bin
(openvino_test) G:\pyopenvino\dist>C:
(openvino_test) C:\Program Files (x86)\Intel\openvino_2021.4.752\bin>setupvars.bat
Python 3.7.12
[setupvars.bat] OpenVINO environment initialized
(openvino_test) C:\Program Files (x86)\Intel\openvino_2021.4.752\bin>cd G:\pyopenvino\dist
(openvino_test) C:\Program Files (x86)\Intel\openvino_2021.4.752\bin>G:
(openvino_test) G:\pyopenvino\dist>app.exe
start add
end
(openvino_test) G:\pyopenvino\dist>
标签:openvino,pyinstaller,2021.4,test,libs,path,os,pyopenvino From: https://www.cnblogs.com/chen1880/p/17660269.html