Python Error: EngineError: Unable to connect to MATLAB session
11 次查看(过去 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!