MATLAB Answers

How to correctly install MATLAB Engine API for Python 3.7 on Windows 10

101 views (last 30 days)
Caroline Alden
Caroline Alden on 12 Sep 2019
Edited: Shrinidhi KR on 6 May 2020
I have attempted to install the MATLAB Engine API for Python 3.7 on Windows 10. I followed the directions exactly as given in https://www.mathworks.com/matlabcentral/answers/475298-matlab-engine-api-for-python-3-7. However, when I go to a Python script and attempt "Import matlab.engine", I get the following error (note: sometimes the final error reads "The operating system cannot run 1%." instead of "The specificed module could not be found". Curiously, I can "import matlab" just fine.
ModuleNotFoundError Traceback (most recent call last)
c:\users\david\appdata\local\programs\python\python37\lib\site-packages\matlab\engine\__init__.py in <module>
44 try:
---> 45 pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
46 except:
c:\users\david\appdata\local\programs\python\python37\lib\importlib\__init__.py in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _find_and_load(name, import_)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'matlabengineforpython3_7'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
c:\users\david\appdata\local\programs\python\python37\lib\site-packages\matlab\engine\__init__.py in <module>
60 os.environ[_envs[_arch]] = _bin_dir
---> 61 pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
62 except Exception as e:
c:\users\david\appdata\local\programs\python\python37\lib\importlib\__init__.py in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _find_and_load(name, import_)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _load_unlocked(spec)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in module_from_spec(spec)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap_external.py in create_module(self, spec)
c:\users\david\appdata\local\programs\python\python37\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-1-754f7d50ef2a> in <module>
----> 1 import matlab.engine
c:\users\david\appdata\local\programs\python\python37\lib\site-packages\matlab\engine\__init__.py in <module>
62 except Exception as e:
63 raise EnvironmentError('Please reinstall MATLAB Engine for Python or contact '
---> 64 'MathWorks Technical Support for assistance: %s' % e)
65
66
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: DLL load failed: The specified module could not be found.

  0 Comments

Sign in to comment.

Answers (1)

Shrinidhi KR
Shrinidhi KR on 6 May 2020
Edited: Shrinidhi KR on 6 May 2020
Have you verified that you have matlab_kernel installed as mentioned in the matlab answer that you have referred?
You can verify if the it is installed by checking the libraries in your virtual environment or base environment by "pip list" command.
This documentation provides system requirements and installation steps provided by mathworks to setup and install matlab engine: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
Also verify if there are multiple python versions on your system and which version has all the necessary libraries like matlab_kernel and matlab engine installed.
I would suggest you have a separate virtual environment with required python version for matlab engine (i.e python3.7 or 3.6) and install engine and matlab kernel there, this might resolve the issues related to multiple python versions if it exists.

  0 Comments

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!