Cannot start matlab engine in python

8 views (last 30 days)
Vadim Chavarha
Vadim Chavarha on 17 Nov 2022
Answered: Rushikesh on 3 Oct 2024
The following code runs in MacOS on a remote machine with no display:
import matlab.engine
matlab_engine = matlab.engine.start_matlab()
It hangs for some time, mabe a minute or so then fails with the error stack:
Traceback (most recent call last):
File "m.py", line 5, in <module>
matlab_engine = matlab.engine.start_matlab()
File "/PythonEnv2/lib/python2.7/site-packages/matlab/engine/__init__.py", line 130, in start_matlab
eng = future.result()
File "/PythonEnv2/lib/python2.7/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/PythonEnv2/lib/python2.7/site-packages/matlab/engine/matlabfuture.py", line 87, in result
handle = pythonengine.getMATLAB(self._future)
matlab.engine.EngineError: Connection to process with Exchange: " " was lost.
Any idea what can cause this.
My matlabengine package matlabengineforpython==9.13
Matlab itself: MATLAB_R2022b
The license is set up as environment variable MLM_LICENSE_FILE=...
Ping to all license servers specified in MLM_LICENSE_FILE works.
  2 Comments
Navya Singam
Navya Singam on 22 Nov 2022
1) Is this issue happening sporadically?
2) Have you tried having a MATLAB session running and using the following command to Connect shared MATLAB session to MATLAB Engine for Python
import matlab.engine
eng = matlab.engine.connect_matlab()
Is the above command running without any issue?
J.
J. on 17 Feb 2023
Hi @Navya Singam I encountered the same error in the docker cloud environment. Due to the nature of my numerical experiments, I cannot start matlab session first and connect to it in python. Is there any workaround? (I also tried using background = True without any success.) Thanks!

Sign in to comment.

Answers (1)

Rushikesh
Rushikesh on 3 Oct 2024
The issue may arise due to several factors such as licensing configuration problems, network issues, resource constraints on the server, or misconfigurations within the server environment.
Ensure that the licensing configuration is correct. You can try executing the ‘start_matlab’ function with the full path to the ‘network.lic’ file. This can be done in the server's command prompt.
%For example in python
eng = matlab.engine.start_matlab("-c /full/path/to/network.lic")
If you are using Docker, I recommend referring to the following MATLAB Central answer for a comprehensive guide on starting the MATLAB Engine within a Docker container:

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!