How to call python script contains "pytorch" module normally
24 views (last 30 days)
Show older comments
I want to call a python script, which uses the pytorch module, in matlab script, but then it occures error:
Traceback (most recent call last):
File "/home/usrs/xxxxx/xxxxxx/test.py", line 9, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
I have checked pyversion and pyenv and I can use other module (e.g. numpy), but I can't clear this error.
I know I can use pytorch model in MATLAB by converting from pytorch model to ONNX model.
However, I want to run this python script because it's easier than converting.
Thank you so much!
0 Comments
Accepted Answer
Yongjian Feng
on 4 Nov 2021
Edited: Yongjian Feng
on 4 Nov 2021
Append the path to torch to an env var called PYTHONPATH. Do this from matlab command line window:
setenv('PYTHONPATH', [getenv('PYTHONPATH') ';C:\the_path_to_torch']);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!