Filter löschen
Filter löschen

Python Error: EngineError: Unable to connect to MATLAB session

11 Ansichten (letzte 30 Tage)
tane martin
tane martin am 18 Sep. 2020
Bearbeitet: Ahmed Abida am 25 Feb. 2021
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 Kommentare
Ahmed Abida
Ahmed Abida am 24 Feb. 2021
Bearbeitet: Ahmed Abida am 25 Feb. 2021
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 am 25 Feb. 2021
Bearbeitet: Ahmed Abida am 25 Feb. 2021
same problem since 2017 ... https://de.mathworks.com/matlabcentral/answers/595768-python-error-engineerror-unable-to-connect-to-matlab-session

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by