Usage of "Matlab python engine" from python executed by Matlab

조회 수: 1 (최근 30일)
Patrick
Patrick 2017년 4월 26일
답변: Hitesh 2025년 1월 31일
To reproduce the error, set up an Matlab + python environment with installed matlab.engine.
Executing the code
py.importlib.import_module('matlab.engine')
gives the following error message:
Error using enginesession>__init__ (line 8)
Python Error: EngineError: MATLAB process session cannot be initialized.
Error in __init__><module> (line 80)
_session = EngineSession()
Error in <frozen importlib>_call_with_frames_removed (line 222)
Error in <frozen importlib>exec_module (line 673)
Error in <frozen importlib>_load_unlocked (line 673)
Error in <frozen importlib>_find_and_load_unlocked (line 958)
Error in <frozen importlib>_find_and_load (line 969)
Error in <frozen importlib>_gcd_import (line 986)
Error in __init__>import_module (line 126)
return _bootstrap._gcd_import(name[level:], package, level)
The basic problem I want to solve by using matlab.engine is to have callbacks from python to Matlab. The trivial solution "passing function handles" is not possible. Is there a different approach possible?
  댓글 수: 2
Tomasz Wyrowinski
Tomasz Wyrowinski 2017년 7월 26일
I've also encountered that problem. Is there any solution or workaround maybe?
Ishaan
Ishaan 2025년 1월 23일
Hey, this issue is not reproducable in MATLAB R2024b with python 3.12. It appears that they fixed it.
Please specify the version if you are still encountering this issue.

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

답변 (1개)

Hitesh
Hitesh 2025년 1월 31일
Hi Patrick,
I too encountered this error in MATLAB R2023b, the workaround that worked for me was to reinstall the "matlabengine" module. Kindly ensure that you need to run following command in this directory "matlabroot\extern\engines\python".
pip install matlabengine
I made a simple simulink model in python. I have saved the model and attached it for your reference.Kindly refer to the below image for the python script.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by