MATLAB: Do I get a “DLL load failed” error when importing MATLAB Engine in Python

engineenvironmenterrorimportMATLAB

Why do I get a "DLL load failed" error when importing MATLAB Engine in Python? I installed the supported version of Python 2.7 and get the following error when trying to execute the command "> import matlab.engine":
trying C:\Python27\lib\site-packages\matlabengineforpython2_7.pyd
# trying C:\Python27\lib\site-packages\matlabengineforpython2_7.py
# trying C:\Python27\lib\site-packages\matlabengineforpython2_7.pyw
# trying C:\Python27\lib\site-packages\matlabengineforpython2_7.pyc
# trying C:\Python27\lib\site-packages\matlab\matlabengineforpython2_7.pyd
# trying C:\Python27\lib\site-packages\matlab\matlabengineforpython2_7.py
# trying C:\Python27\lib\site-packages\matlab\matlabengineforpython2_7.pyw
# trying C:\Python27\lib\site-packages\matlab\matlabengineforpython2_7.pyc
# trying C:\Program Files\MATLAB\R2017b\extern\engines\python\dist\matlab\engine\win64\matlabengineforpython2_7.pyd
# clear[1] _module_folder
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\matlab\engine\__init__.py", line 62, in <module>
'MathWorks Technical Support for assistance: %s' % e)
EnvironmentError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: DLL load failed: The specified procedure could not be found.

Best Answer

The issue is related to library conflict. For example, a custom version of "tbb.dll" is loaded, while Python Engine only works with the version shipped with MATLAB.
From the Process Monitor logs, we can find that "tbb.dll" and "tbbmalloc.dll" are loaded from "c:\Windows\System32" folder.
Renaming the files "tbb.dll" and "tbbmalloc.dll" from "c:\Windows\System32" folder will resolve the issue.