Cannot install matlab python engine API

조회 수: 35 (최근 30일)
Makis
Makis 2022년 7월 3일
댓글: Matthew Fall 2023년 1월 11일
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
Matthew Fall
Matthew Fall 2023년 1월 11일
I'm having the same issue for both Matlab R2021a and R2021b.

댓글을 달려면 로그인하십시오.

답변 (1개)

Harimurali
Harimurali 2022년 7월 4일
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:
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()
Please refer the following MATLAB tutorial on using MATLAB engine.
  댓글 수: 1
Matthew Fall
Matthew Fall 2023년 1월 11일
It looks like Makis is already following these steps.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by