From c3fc40052c94552e20a14828ec87a0e420b70670 Mon Sep 17 00:00:00 2001 From: Mikhail Ryzhov Date: Tue, 23 Mar 2021 17:32:08 +0300 Subject: [PATCH] Python 3.8 support (#4629) * Python 3.8 support * Get path from setupvars --- .../src/openvino/inference_engine/__init__.py | 25 ++++++++++----- .../offline_transformations/__init__.py | 25 ++++++++++----- ngraph/python/src/ngraph/impl/__init__.py | 32 +++++++++++-------- scripts/setupvars/setupvars.bat | 9 ++++-- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/__init__.py b/inference-engine/ie_bridges/python/src/openvino/inference_engine/__init__.py index 5ca0763951f..b7ed8b53f9a 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/__init__.py +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/__init__.py @@ -19,17 +19,26 @@ import os import sys if sys.platform == "win32": - # PIP installs openvino dlls 3 directories above in openvino.libs by default - # and this path needs to be visible to the openvino modules + # 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. - openvino_dlls = os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs") - if (3, 8) <= sys.version_info: - # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. - os.add_dll_directory(os.path.abspath(openvino_dlls)) - else: - os.environ["PATH"] = os.path.abspath(openvino_dlls) + ";" + os.environ["PATH"] + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), '..', '..', '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)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] from .ie_api import * __all__ = ['IENetwork', "TensorDesc", "IECore", "Blob", "PreProcessInfo", "get_version"] diff --git a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/__init__.py b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/__init__.py index cf94f15ce34..fc32ec732f1 100644 --- a/inference-engine/ie_bridges/python/src/openvino/offline_transformations/__init__.py +++ b/inference-engine/ie_bridges/python/src/openvino/offline_transformations/__init__.py @@ -4,17 +4,26 @@ import os import sys if sys.platform == "win32": - # PIP installs openvino dlls 3 directories above in openvino.libs by default - # and this path needs to be visible to the openvino modules + # 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. - openvino_dlls = os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs") - if (3, 8) <= sys.version_info: - # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. - os.add_dll_directory(os.path.abspath(openvino_dlls)) - else: - os.environ["PATH"] = os.path.abspath(openvino_dlls) + ";" + os.environ["PATH"] + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), '..', '..', '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)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] from .offline_transformations_api import * __all__ = ['ApplyMOCTransformations'] diff --git a/ngraph/python/src/ngraph/impl/__init__.py b/ngraph/python/src/ngraph/impl/__init__.py index dbdeec584f4..470e58041e6 100644 --- a/ngraph/python/src/ngraph/impl/__init__.py +++ b/ngraph/python/src/ngraph/impl/__init__.py @@ -24,23 +24,27 @@ import os import sys if sys.platform == "win32": - # ngraph.dll is installed 3 directories above by default - # and this path needs to be visible to the _pyngraph module + # Installer, yum, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino modules # - ngraph_dll = os.path.join(os.path.dirname(__file__), "..", "..", "..") - - # PIP installs openvino and ngraph dlls 2 directories above in openvino.libs by default - # and this path needs to be visible to the _pyngraph modules - # - openvino_dlls = os.path.join(os.path.dirname(__file__), "..", "..", "openvino", "libs") # If you're using a custom installation of openvino, # add the location of openvino dlls to your system PATH. - if (3, 8) <= sys.version_info: - # On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. - os.add_dll_directory(os.path.abspath(ngraph_dll)) - os.add_dll_directory(os.path.abspath(openvino_dlls)) - else: - os.environ["PATH"] = os.path.abspath(openvino_dlls) + ";" + os.path.abspath(ngraph_dll) + ";" + os.environ["PATH"] + # + # looking for the libs in the pip installation path by default. + openvino_libs = [os.path.join(os.path.dirname(__file__), '..', '..', '..'), + os.path.join(os.path.dirname(__file__), '..', '..', '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)) + else: + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] from _pyngraph import Dimension from _pyngraph import Function diff --git a/scripts/setupvars/setupvars.bat b/scripts/setupvars/setupvars.bat index e31aeb91505..2cd383112e7 100644 --- a/scripts/setupvars/setupvars.bat +++ b/scripts/setupvars/setupvars.bat @@ -55,7 +55,7 @@ set "HDDL_INSTALL_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\ext set "OPENMP_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\omp\lib" set "GNA_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\gna\lib" -set "PATH=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Release;%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Debug;%HDDL_INSTALL_DIR%\bin;%OPENMP_DIR%;%GNA_DIR%;%PATH%" +set "OPENVINO_LIB_PATHS=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Release;%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\Debug;%HDDL_INSTALL_DIR%\bin;%OPENMP_DIR%;%GNA_DIR%;%OPENVINO_LIB_PATHS%" if exist %INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\arch_descriptions ( set ARCH_ROOT_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\intel64\arch_descriptions ) @@ -65,16 +65,19 @@ set ARCH_ROOT_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\bin\int :: TBB if exist %INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\tbb ( -set "PATH=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\tbb\bin;%PATH%" +set "OPENVINO_LIB_PATHS=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\tbb\bin;%OPENVINO_LIB_PATHS%" set "TBB_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\external\tbb\cmake" ) :: nGraph if exist %INTEL_OPENVINO_DIR%\deployment_tools\ngraph ( -set "PATH=%INTEL_OPENVINO_DIR%\deployment_tools\ngraph\lib;%PATH%" +set "OPENVINO_LIB_PATHS=%INTEL_OPENVINO_DIR%\deployment_tools\ngraph\lib;%OPENVINO_LIB_PATHS%" set "ngraph_DIR=%INTEL_OPENVINO_DIR%\deployment_tools\ngraph\cmake" ) +:: Add libs dirs to the PATH +set "PATH=%OPENVINO_LIB_PATHS%;%PATH%" + :: Check if Python is installed python --version 2>NUL if errorlevel 1 (