Python Error: EngineError: Unable to connect to MATLAB session

6 ビュー (過去 30 日間)
tane martin
tane martin 2020 年 9 月 18 日
編集済み: Ahmed Abida 2021 年 2 月 25 日
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
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
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 ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by