Cannot install matlab python engine API
37 views (last 30 days)
Show older comments
I am having trouble installing the python engine for my matlab 2022 version.
I go to "/Applications/MATLAB_R2022a.app/extern/engines/python" and run "python setup.py install"
Last lines of output look like this:
Extracting matlabengineforpython-R2022a-py3.8.egg to /opt/anaconda3/lib/python3.8/site-packages
matlabengineforpython R2022a is already the active version in easy-install.pth
/opt/anaconda3/lib/python3.8/site-packages/pkg_resources/__init__.py:122: PkgResourcesDeprecationWarning: R2022a is an invalid version and will not be supported in a future release
warnings.warn(
Installed /opt/anaconda3/lib/python3.8/site-packages/matlabengineforpython-R2022a-py3.8.egg
Processing dependencies for matlabengineforpython===R2022a
Finished processing dependencies for matlabengineforpython===R2022a
This looks fine. When I enter python3 and try to import the engine ("import matlab.engine"), i get:
>>> import matlab.engine
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/matlab/engine/__init__.py", line 46, in <module>
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
File "/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matlabengineforpython3_8'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/matlab/engine/__init__.py", line 65, in <module>
pythonengine = importlib.import_module("matlabengineforpython"+_PYTHONVERSION)
File "/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matlabengineforpython3_8'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/anaconda3/lib/python3.8/site-packages/matlab/engine/__init__.py", line 67, in <module>
raise EnvironmentError('Please reinstall MATLAB Engine for Python or contact '
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: No module named 'matlabengineforpython3_8'
1 Comment
Answers (1)
Harimurali
on 4 Jul 2022
I understand that you are unable to install/use the MATLAB engine for Python.
Make sure that the following requirements are satisfied for installing MATLAB engine for Python:
- A licensed version of MATLAB installed on your system.
- Python version compatible with MATLAB is installed. Refer Python versions compatible with MATLAB.
If the above requirements are satisfied you can try the below steps:
1. Open MATLAB as administrator and run the following in the MATLAB command prompt:
>> cd (fullfile(matlabroot,'extern','engines','python'))
>> system('setup.py install')
This will install the MATLAB engine for Python.
2. Now start Python, import the module, and start the MATLAB engine:
import matlab.engine
eng = matlab.engine.start_matlab()
3. For exiting the matlab engine:
eng.quit()
1 Comment
See Also
Categories
Find more on Call MATLAB from Python in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!