|
34 | 34 | logger = logging.getLogger(__name__) |
35 | 35 |
|
36 | 36 | # Auto-discover the OpenVINO C library path from the pip-installed openvino |
37 | | -# package so the C++ backend's dlopen("libopenvino_c.so") works without the |
38 | | -# user having to set LD_LIBRARY_PATH or OPENVINO_LIB_PATH manually. |
| 37 | +# package so the C++ backend's dlopen/LoadLibrary call works without the user |
| 38 | +# having to set LD_LIBRARY_PATH or OPENVINO_LIB_PATH manually. |
39 | 39 | if not os.environ.get("OPENVINO_LIB_PATH"): |
40 | 40 | try: |
41 | 41 | import glob |
|
44 | 44 | spec = importlib.util.find_spec("openvino") |
45 | 45 | if spec is not None and spec.submodule_search_locations: |
46 | 46 | _ov_dir = spec.submodule_search_locations[0] |
47 | | - _ov_libs = sorted( |
48 | | - glob.glob(os.path.join(_ov_dir, "libs", "libopenvino_c.so*")) |
49 | | - ) |
| 47 | + _ov_libs_dir = os.path.join(_ov_dir, "libs") |
| 48 | + if sys.platform == "win32": |
| 49 | + _lib_pattern = os.path.join(_ov_libs_dir, "openvino_c.dll") |
| 50 | + else: |
| 51 | + _lib_pattern = os.path.join(_ov_libs_dir, "libopenvino_c.so*") |
| 52 | + _ov_libs = sorted(glob.glob(_lib_pattern)) |
50 | 53 | if _ov_libs: |
51 | 54 | os.environ["OPENVINO_LIB_PATH"] = _ov_libs[0] |
| 55 | + if sys.platform == "win32": |
| 56 | + os.add_dll_directory(_ov_libs_dir) |
52 | 57 | else: |
53 | 58 | logger.warning( |
54 | | - "OpenVINO package found but libopenvino_c.so not in %s; " |
| 59 | + "OpenVINO package found but %s not in %s; " |
55 | 60 | "set OPENVINO_LIB_PATH manually if needed", |
56 | | - os.path.join(_ov_dir, "libs"), |
| 61 | + "openvino_c.dll" if sys.platform == "win32" else "libopenvino_c.so", |
| 62 | + _ov_libs_dir, |
57 | 63 | ) |
58 | | - del _ov_libs, _ov_dir, spec |
| 64 | + del _ov_libs, _ov_libs_dir, _lib_pattern, _ov_dir, spec |
59 | 65 | except Exception as e: |
60 | 66 | logger.debug("OpenVINO auto-discovery failed: %s", e) |
61 | 67 |
|
|
0 commit comments