Matlab crashes when importing pytorch library

조회 수: 11 (최근 30일)
Daria Ri
Daria Ri 2021년 7월 30일
댓글: Daria Ri 2021년 8월 4일
I'm calling user-defined python module from matlab script that includes PyTorch library. The following line crashes Matlab:
def myfunc():
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
Any ideas on how to fix this?
Thanks in advance

답변 (1개)

Vignesh Murugavel
Vignesh Murugavel 2021년 8월 1일
Using out-of-process execution mode will avoid these conflicts. For this reason, using out-of-process mode is the best practice when using the Python Interface. Use the pyenv command to run in out-of-process mode.
>> pyenv("Version","<path to python executable>", "ExecutionMode", "OutOfProcess")
  댓글 수: 1
Daria Ri
Daria Ri 2021년 8월 4일
Thank you @Vignesh Murugavel for the answer
Yes, this fixes the issue of matlab crashing but then I need to call matlab script in my python code , so as soon as I include the matlab engine in python module python interpreter terminates
eng = matlab.engine.start_matlab()
eng.cd(r'/home/pathToMyMatlab', nargout=0)
with the following error:
Python process terminated unexpectedly. To restart the Python interpreter, first call "terminate(pyenv)" and then call a Python function.
This does not happen when ExecutionMode of python interpreter is the default InProcess.
Please help!

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

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by