importlib.reload(matlab.engine) is not working
Hey,
I try to switch the python engine version in one single class. I added here a small example. Based on the used matlab version I want do add matlab.engine version dynamically. I tested many ways – importlib.reload(<matlabVersion>) is not working. What is the best way
import sys
import re
import importlib
matlab2017a ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab17aPy35Libsite-packages"
matlab2016b ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packages"
sys.path.append(matlab2016b)
import matlab.engine
print(matlab.__file__)
print(matlab.engine.find_matlab())
def __RemoveMatlabEngineFromSysPath__(deliveredLibs):
for p in sys.path:
if p.find(deliveredLibs) != -1:
sys.path.remove(p)
__RemoveMatlabEngineFromSysPath__(matlab2016b)
sys.path.append(matlab2017a)
matlab = importlib.reload(matlab.engine)
print(matlab.engine.__file__)
print(matlab.engine.find_matlab())
Output:
File "d:/CodeArea/ModelQualityInterface/core/Tools/MatlabSimulink/test_multipleMatlabVersions.py", line 31, in <module>MatlabSimulink/test_multipleMatlabVersions.py", line
31, in <module> t__.py", line 166, in reload
matlab = importlib.reload(matlab.engine)
File "c:Program FilesPython35libimportlib__ini_exect__.py", line 166, in reload 697, in exec_module
_bootstrap._exec(spec, module) _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 626, in MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengine__init__.py", line 80, in <module>
_exec
File "<frozen importlib._bootstrap_external>", lineMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__ 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in not be initialized.
_call_with_frames_removed el__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__engine__init__.py", line 80, in <module>
_session = EngineSession() MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__
pythonengine.createProcess()
matlab.engine.EngineError: MATLAB process session cannot be initialized.
Exception ignored in: <bound method EngineSession.__del__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
Traceback (most recent call last):
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__
self.release()
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
if self._process_created:
AttributeError: ‘EngineSession’ object has no attribute ‘_process_created’Hey,
I try to switch the python engine version in one single class. I added here a small example. Based on the used matlab version I want do add matlab.engine version dynamically. I tested many ways – importlib.reload(<matlabVersion>) is not working. What is the best way
import sys
import re
import importlib
matlab2017a ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab17aPy35Libsite-packages"
matlab2016b ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packages"
sys.path.append(matlab2016b)
import matlab.engine
print(matlab.__file__)
print(matlab.engine.find_matlab())
def __RemoveMatlabEngineFromSysPath__(deliveredLibs):
for p in sys.path:
if p.find(deliveredLibs) != -1:
sys.path.remove(p)
__RemoveMatlabEngineFromSysPath__(matlab2016b)
sys.path.append(matlab2017a)
matlab = importlib.reload(matlab.engine)
print(matlab.engine.__file__)
print(matlab.engine.find_matlab())
Output:
File "d:/CodeArea/ModelQualityInterface/core/Tools/MatlabSimulink/test_multipleMatlabVersions.py", line 31, in <module>MatlabSimulink/test_multipleMatlabVersions.py", line
31, in <module> t__.py", line 166, in reload
matlab = importlib.reload(matlab.engine)
File "c:Program FilesPython35libimportlib__ini_exect__.py", line 166, in reload 697, in exec_module
_bootstrap._exec(spec, module) _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 626, in MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengine__init__.py", line 80, in <module>
_exec
File "<frozen importlib._bootstrap_external>", lineMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__ 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in not be initialized.
_call_with_frames_removed el__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__engine__init__.py", line 80, in <module>
_session = EngineSession() MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__
pythonengine.createProcess()
matlab.engine.EngineError: MATLAB process session cannot be initialized.
Exception ignored in: <bound method EngineSession.__del__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
Traceback (most recent call last):
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__
self.release()
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
if self._process_created:
AttributeError: ‘EngineSession’ object has no attribute ‘_process_created’ Hey,
I try to switch the python engine version in one single class. I added here a small example. Based on the used matlab version I want do add matlab.engine version dynamically. I tested many ways – importlib.reload(<matlabVersion>) is not working. What is the best way
import sys
import re
import importlib
matlab2017a ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab17aPy35Libsite-packages"
matlab2016b ="d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packages"
sys.path.append(matlab2016b)
import matlab.engine
print(matlab.__file__)
print(matlab.engine.find_matlab())
def __RemoveMatlabEngineFromSysPath__(deliveredLibs):
for p in sys.path:
if p.find(deliveredLibs) != -1:
sys.path.remove(p)
__RemoveMatlabEngineFromSysPath__(matlab2016b)
sys.path.append(matlab2017a)
matlab = importlib.reload(matlab.engine)
print(matlab.engine.__file__)
print(matlab.engine.find_matlab())
Output:
File "d:/CodeArea/ModelQualityInterface/core/Tools/MatlabSimulink/test_multipleMatlabVersions.py", line 31, in <module>MatlabSimulink/test_multipleMatlabVersions.py", line
31, in <module> t__.py", line 166, in reload
matlab = importlib.reload(matlab.engine)
File "c:Program FilesPython35libimportlib__ini_exect__.py", line 166, in reload 697, in exec_module
_bootstrap._exec(spec, module) _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 626, in MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengine__init__.py", line 80, in <module>
_exec
File "<frozen importlib._bootstrap_external>", lineMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__ 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in not be initialized.
_call_with_frames_removed el__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__engine__init__.py", line 80, in <module>
_session = EngineSession() MatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 8, in __init__
pythonengine.createProcess()
matlab.engine.EngineError: MATLAB process session cannot be initialized.
Exception ignored in: <bound method EngineSession.__del__ of <matlab.engine.enginesession.EngineSession object at 0x00000212C1A2E7B8>>
Traceback (most recent call last):
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 14, in __del__
self.release()
File "d:CodeAreaModelQualityInterfacecoreToolsMatlabSimulinkmatlab16bPy35Libsite-packagesmatlabengineenginesession.py", line 17, in release
if self._process_created:
AttributeError: ‘EngineSession’ object has no attribute ‘_process_created’ python, import MATLAB Answers — New Questions