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

Merged
merged 3 commits into from
Jun 2, 2025

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?

@ekomarova ekomarova linked an issue Jun 2, 2025 that may be closed by this pull request
@ekomarova ekomarova merged commit 7fe7c5d into master Jun 2, 2025
25 checks passed
@ekomarova ekomarova deleted the wheels/fix_windows_venv branch June 2, 2025 16:15
urob added a commit to urob/numpy-mkl that referenced this pull request Jun 2, 2025
The fix in IntelPython/mkl-service#79 only
works when all libraries are installed in default paths while our own
patch dynamically detects the library path and hence works much more
generally.
@vtavana vtavana mentioned this pull request Jun 4, 2025
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.

Issue importing mkl on Windows
3 participants