Python Error: EngineError: Unable to connect to MATLAB session
조회 수: 6 (최근 30일)
이전 댓글 표시
Hey all,
I'm experiencing the following error when trying to share the Matlab engine with Python:
Error using matlabfuture>result (line 87)
Python Error: EngineError: Unable to connect to MATLAB session 'Matlab_Engine_Test'.
Error in futureresult>result (line 67)
Error in __init__>connect_matlab (line 177)
Error in client>testing_output (line 204)
The code works by running a Matlab script that creates a Python Object. Then it calls the class method test_method():
if ~matlab.engine.isEngineShared
matlab.engine.shareEngine('Matlab_Engine_Test')
end
a = py.py_lib.py_class;
a.test_method()
The method test_method() attempts to connect to the Matlab engine and then create a variable in the workspace:
def testing_output(self):
eng = matlab.engine.connect_matlab('Matlab_Engine_Test')
eng.workspace['temp'] = 1223
return names
But the connection fails and produces the previously mentioned error.
Based on the documentation it looks to me like this should work. Anyone have any ideas?
EDIT: I should clarify why I'm building it this way instead of just having the Python method return a value as you'd expect.
I'm testing how to connect Python to the "active" workspace. In practice the method that will actually run is a callback function triggered by an API returning data that'll need to retuirn values to the workspace. The best way I can think is to add a variable to the workspace through the shared engine accessed through Python. (If anyone has better suggestions, I'm all ears).
So to test this out I just figured I'd do it without the callback and possible issues that could create and just use a test method I could call directly.
댓글 수: 2
Ahmed Abida
2021년 2월 24일
편집: Ahmed Abida
2021년 2월 25일
Hi, i have the same problem, I understand that there is a conflict when you lunch the python modul from the same Matlab session.. I have the same problem but there is no documentation
Ahmed Abida
2021년 2월 25일
편집: Ahmed Abida
2021년 2월 25일
same problem since 2017 ... https://de.mathworks.com/matlabcentral/answers/595768-python-error-engineerror-unable-to-connect-to-matlab-session
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!