Issue importing mkl on Windows
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.
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.
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?