Why does Python 3.6 fail to import MATLAB Engine and give a "DLL load failed" error?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 11 Feb 2021
Modificato: MathWorks Support Team
il 7 Ago 2024
I am using MATLAB R2018a. I have installed CPython 3.6.7 and installed MATLAB engine as mentioned in the documentation page obtained by running the following command on MATLAB R2018a:
web(fullfile(docroot, 'matlab/matlab_external/install-the-matlab-engine-for-python.html'))
But I am getting the below error on executing "
import matlab.engine":
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
File "C:\Programs\Python\Python36\lib\importlib\_
_init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matlabengineforpython3_6'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Programs\Python\Python36\lib\site-packag
es\matlab\engine\__init__.py", line 59, in <module>
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSIO
N)
File "C:\Programs\Python\Python36\lib\importlib\_
_init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified procedure could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python36\lib\site-packag
es\matlab\engine\__init__.py", line 62, in <module>
'MathWorks Technical Support for assistance: %s' % e)
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: DLL load failed: The specified procedure could not be found.
The file C:\Program Files\MATLAB\R2018a\extern\engines\python\dist\matlab\engine\win64\matlabengineforpython3_6.pyd also got created.
Please follow the below link to search for the required information regarding the current release:
https://www.mathworks.com/help/Risposta accettata
MathWorks Support Team
il 7 Ago 2024
Modificato: MathWorks Support Team
il 7 Ago 2024
The issue is due to loading one of the DLL libraries that MATLAB Engine needs from the wrong location. For example, Python is loading "tbb.dll" and/or "tbbmalloc.dll" from the system folder "C:\Windows\System32" instead of loading them from "<matlabroot>/bin/win64". You can use Process Monitor to try to determine which DLL is causing the issue.
As a workaround, and using tbb.dll as an example, rename these files in the system folder so that Python can no longer find them. Other workarounds include:
1) Copying the MathWorks version of the DLL to the same folder as the Python executable (not into a subfolder), and leave the "System32" version as it originally was.
2) Place the MathWorks version of the DLL into "System32" (after copying or renaming the original so it does not get overwritten). This may allow all applications to use the same version of "tbb.dll", but there is a chance that it will not compatible.
3) Determine what application or applications might be using the "tbb.dll" file that is located in "C:\Windows\System32" and copy that version to the same folder as those application executables. Then remove the DLL from "System32" entirely. A tool called Process Explorer can help by showing which DLLs have been loaded by a particular open application. However, this would require opening any application which might have put the library into the "System32" directory, which may be a time-consuming process. For more information on Process Explorer, please refer to the following page:
Which one work best will depend on your workflow and use case.
See this link for other issues related to "ModuleNotFoundError: No module named 'matlabengineforpythonX_X" errors.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Call MATLAB from Python in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!