Skip to content

Commit fdde3d0

Browse files
authored
Support dpnp in virtual environment on Windows out of the box (#2242)
Since location of "Library\bin" in the virtual environment is not on the default search path, importing of `dpnp` fails due to unmet dependencies towards oneMKL libraries. The PR proposes to extend `"PATH"` environment on Windows in the virtual environment with a path to `"Library\bin"` directory.
1 parent cabc0d7 commit fdde3d0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

dpnp/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# *****************************************************************************
2626

2727
import os
28+
import sys
2829

2930
mypath = os.path.dirname(os.path.realpath(__file__))
3031

@@ -45,10 +46,22 @@
4546
if hasattr(os, "add_dll_directory"):
4647
os.add_dll_directory(mypath)
4748
os.add_dll_directory(dpctlpath)
49+
4850
os.environ["PATH"] = os.pathsep.join(
4951
[os.getenv("PATH", ""), mypath, dpctlpath]
5052
)
5153

54+
# For virtual environments on Windows, add folder with DPC++ libraries
55+
# to the DLL search path
56+
if sys.base_exec_prefix != sys.exec_prefix and os.path.isfile(
57+
os.path.join(sys.exec_prefix, "pyvenv.cfg")
58+
):
59+
dll_path = os.path.join(sys.exec_prefix, "Library", "bin")
60+
if os.path.isdir(dll_path):
61+
os.environ["PATH"] = os.pathsep.join(
62+
[os.getenv("PATH", ""), dll_path]
63+
)
64+
5265
# Borrowed from DPCTL
5366
from dpctl.tensor import DLDeviceType
5467

0 commit comments

Comments
 (0)