Import matlab.engine error

조회 수: 17 (최근 30일)
Tomasz Wyrowinski
Tomasz Wyrowinski 2017년 7월 14일
답변: Isaac Lenton 2018년 8월 9일
In Matlab script I am trying to create a Python object that holds reference to the Matlab session. To do that I am passing shared engine name to Python object constructor and trying to find matlab instance using matlab.engine library. During library importing Python raises an exception:
>> py.importlib.import_module('task_monitor')
Error using enginesession>__init__ (line 8)
Python Error: EngineError: MATLAB process session cannot be initialized.
Error in __init__><module> (line 80)
_session = EngineSession()
Error in task_monitor><module> (line 1)
import matlab.engine
Error in __init__>import_module (line 37)
__import__(name)
Python class definition
import matlab.engine
class TaskMonitor:
def __init__(self, matlabName):
try:
self.matlabEngine = matlab.engine.connect_matlab(matlabName)
except matlab.engine.EngineError as err:
print('Could not connect to Matlab: ' + str(err))
Matlab script creating Python object
function init()
if ~matlab.engine.isEngineShared
matlab.engine.shareEngine;
end
sessionName = matlab.engine.engineName;
global monitor;
monitor = py.task_monitor.TaskMonitor(sessionName);
end
When I try to instantiate TaskMonitor in Python's console everything's fine and the object s being created. Is it somehow different while creating it from within Matlab console?
Looks like importing matlab.engine in Python script that's run from within Matlab is not working well.
  댓글 수: 3
Tomasz Wyrowinski
Tomasz Wyrowinski 2017년 7월 26일
The issue was also reported in that question:
Christian Dreher
Christian Dreher 2017년 8월 3일
I have the same issue and would really appreciate any help.

댓글을 달려면 로그인하십시오.

답변 (1개)

Isaac Lenton
Isaac Lenton 2018년 8월 9일
I'm not sure about a safe workaround, but something that seems to work is removing the _session = EngineSession() line and corresponding cleanup line in the matlab.engine init script. Not sure how safe this is, but it seems to work.

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by