Can not connect to Matlab session from Python, I can start matlab engine but can not connect from python
7 views (last 30 days)
Show older comments
In python:
import matlab.engine
print(matlab.engine.find_matlab())
('MATLAB_9012',)
eng = matlab.engine.connect_matlab('MATLAB_9012')
eng.sqrt(4.0)
EngineError Traceback (most recent call last) Cell In[132], line 1----> 1 eng = matlab.engine.connect_matlab('MATLAB_9012') 2 eng.sqrt(4.0) File ~\anaconda3\Lib\site-packages\matlab\engine\__init__.py:201, in connect_matlab(name, **kwargs) 199 future = FutureResult(name=name, attach=True) 200 if not background: --> 201 eng = future.result() 202 return eng 203 else: File ~\anaconda3\Lib\site-packages\matlab\engine\futureresult.py:62, in FutureResult.result(self, timeout) 59 if timeout < 0: 60 raise TypeError(pythonengine.getMessage('TimeoutCannotBeNegative')) ---> 62 return self.__future.result(timeout) File ~\anaconda3\Lib\site-packages\matlab\engine\matlabfuture.py:87, in MatlabFuture.result(self, timeout) 84 else: 85 raise TimeoutError(pythonengine.getMessage('LaunchMatlabTimeout')) ---> 87 handle = pythonengine.getMATLAB(self._future) 88 eng = MatlabEngine(handle) 89 self._matlab = eng EngineError: Unable to connect to MATLAB session 'MATLAB_9012'.
-----------------------------------------------------------------------------------
If I do this:
import matlab.engine
# Start the MATLAB engine
eng = matlab.engine.start_matlab()
# Check if the engine is running
print("MATLAB Engine started:", eng)
MATLAB Engine started: <matlab.engine.matlabengine.MatlabEngine object at 0x0000024483C419A0>
I can start Matlab engine but I can not connect to a running Matlab session????
Answers (1)
See Also
Categories
Find more on Call MATLAB from Python in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!