Skip to content
New issue

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

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

Already on GitHub? # to your account

Issue importing mkl on Windows #23

Open
ma-sadeghi opened this issue Oct 23, 2021 · 2 comments
Open

Issue importing mkl on Windows #23

ma-sadeghi opened this issue Oct 23, 2021 · 2 comments

Comments

@ma-sadeghi
Copy link

ma-sadeghi commented Oct 23, 2021

Here's how to reproduce the bug:

pip install mkl mkl-service
python -c "import mkl"

and here's the output:

Collecting mkl
  Downloading mkl-2021.4.0-py2.py3-none-win_amd64.whl (228.5 MB)
Collecting mkl-service
  Downloading mkl_service-2.4.0-0-cp37-cp37m-win_amd64.whl (43 kB)
Collecting tbb==2021.*
  Downloading tbb-2021.4.0-py3-none-win_amd64.whl (268 kB)
Collecting intel-openmp==2021.*
  Downloading intel_openmp-2021.4.0-py2.py3-none-win_amd64.whl (3.5 MB)
Collecting six
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: tbb, intel-openmp, six, mkl, mkl-service
Successfully installed intel-openmp-2021.4.0 mkl-2021.4.0 mkl-service-2.4.0 six-1.16.0 tbb-2021.4.0
WARNING: You are using pip version 21.3; however, version 21.3.1 is available.
You should consider upgrading via the 'c:\hostedtoolcache\windows\python\3.7.9\x64\python.exe -m pip install --upgrade pip' command.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\hostedtoolcache\windows\Python\3.7.9\x64\lib\site-packages\mkl\__init__.py", line 49, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
Error: Process completed with exit code 1.
@ma-sadeghi ma-sadeghi changed the title Issue import mkl on Windows Issue importing mkl on Windows Oct 23, 2021
@Azreal42
Copy link

Azreal42 commented Apr 18, 2022

Hi,

I'm a bit late to the party but I've just had the same issue. I was able to fix it by adding to the path and directory for dlls, the Lib dir of the venv (where the mkl package install the DLLs)
You need to patch the __init__.py by adding this :


def init_path_for_mkl():
    try:
        path = os.path.join(os.environ['VIRTUAL_ENV'], "Library\\bin")
        try:
            os.add_dll_directory(path)
        except Exception:
            pass
        environ_path = os.environ.get('PATH', '')
        if path not in environ_path:
            os.environ['PATH'] = os.pathsep.join((path, environ_path))

    except Exception:
        pass

init_path_for_mkl()

It will only work if you're in a virtual env (if your not, just add the path to your PATH env var).
You can then rebuild the wheel with this code and voila.

@Alexander-Serov
Copy link

I am also having this issue. Do you think it's related to a new version of mkl of was it always present?

@GregGodin In your snippet above, "Library\bin" is not a full windows path. Do I understand correctly that it refers to the mkl installation path?

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

No branches or pull requests

3 participants