Skip to content

Support mkl-service in virtual environment out of the box #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ekomarova
Copy link
Collaborator

@ekomarova ekomarova commented May 27, 2025

Since location of "Library\bin" in the virtual environment is not on the default search path, importing of mkl_service fails.
This change introduces "_init_helper.py" file which implements the following logic using built-in os Python module:

  • If os.add_dll_directory attribute exists, and VIRTUAL_ENV environment variable is set, and os.path.join(os.environ["VIRTUAL_ENV"], "Library", "bin") folder exists, call os.add_dll_directory with that directory

@urob
Copy link

urob commented May 27, 2025

Why not dynamically detect the location of the libraries using metadata? This works more general as long as the mkl package is installed in the runtime environment. In particular, it would would also take care of #23.

from importlib.metadata import files

dll = next(p for p in files("mkl") if p.match("*mkl_rt*.dll"))
dll_dir = dll.locate().resolve().parent
os.add_dll_directory(dll_dir)

Here's a complete patch which handles errors and also works on Linux:
https://github.com/urob/numpy-mkl/blob/main/patches/mkl-service/dll_directory.patch

If this looks good, I'd be happy to submit a PR along those lines.

@ekomarova
Copy link
Collaborator Author

Can I merge it? Any objections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants