Matlab crashes when importing pytorch library
7 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Vignesh Murugavel
on 1 Aug 2021
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")
See Also
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!