1

I am trying to run a function written in matlab in a python script using matlab.engine.

The first time I run the script everything works fine, but when I try to run the script again I get the error "ImportError: cannot import name 'TimeoutError'" on importing the matlab engine. Restarting the kernel allows me to run the script again. I am also using import matlab.engine and not from matlab.engine import to avoid circular importing.

Any suggestions on how I can solve the issue? I am using Ubuntu 16.04 and working with spyder.

Many Thanks!

user11573
  • 21
  • 2

1 Answers1

0

I get a similar running error. But after trying several times, I found that for the same *.py manuscript, the phrase import matlab.engine and eng = matlab.engine.start_matlab() should be implemented only once

I commented them, by doing this I can re-run the script *.py again.

Otherwise, it will post the error

ImportError: cannot import name 'TimeoutError'.

I think using the import matlab.engine to start a new MATLABĀ® process is just like to open a door before we close the door, everyone can enter the room or go out again and again, but do not need open the door again because it is not closed yet.

"Restarting the kernel" is just like close the door automatically (the Python stops the engine and its MATLAB process).

wscourge
  • 10,657
  • 14
  • 59
  • 80