Skip to content

Commit

Permalink
Support dpnp in virtual environment on Windows out of the box (#2242)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
antonwolfy authored Dec 19, 2024
1 parent cabc0d7 commit fdde3d0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dpnp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# *****************************************************************************

import os
import sys

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

Expand All @@ -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

Expand Down

0 comments on commit fdde3d0

Please sign in to comment.