From c87e9c8b00f03e033b8436aecf20a1626e2fe5d6 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 19 Dec 2024 21:10:12 +0100 Subject: [PATCH] Support dpnp in vritual environment out of the box --- dpnp/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dpnp/__init__.py b/dpnp/__init__.py index bb285d5029bd..8a4d77c1e668 100644 --- a/dpnp/__init__.py +++ b/dpnp/__init__.py @@ -25,6 +25,7 @@ # ***************************************************************************** import os +import sys mypath = os.path.dirname(os.path.realpath(__file__)) @@ -45,10 +46,22 @@ if hasattr(os, "add_dll_directory"): os.add_dll_directory(mypath) os.add_dll_directory(dpctlpath) + os.environ["PATH"] = os.pathsep.join( [os.getenv("PATH", ""), mypath, dpctlpath] ) + # For virtual environments on Windows, add folder with DPC++ libraries + # to the DLL search path + if sys.base_exec_prefix != sys.exec_prefix and os.path.isfile( + os.path.join(sys.exec_prefix, "pyvenv.cfg") + ): + dll_path = os.path.join(sys.exec_prefix, "Library", "bin") + if os.path.isdir(dll_path): + os.environ["PATH"] = os.pathsep.join( + [os.getenv("PATH", ""), dll_path] + ) + # Borrowed from DPCTL from dpctl.tensor import DLDeviceType