フィルターのクリア

How to call python script contains "pytorch" module normally

17 ビュー (過去 30 日間)
Shohei Uchigasaki
Shohei Uchigasaki 2021 年 11 月 1 日
回答済み: Navid Hashemi 2023 年 2 月 23 日
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.
In addition, I checked this answer, but I can't understand well. So I hope help.
Thank you so much!

採用された回答

Yongjian Feng
Yongjian Feng 2021 年 11 月 4 日
編集済み: Yongjian Feng 2021 年 11 月 4 日
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']);
  2 件のコメント
Shohei Uchigasaki
Shohei Uchigasaki 2021 年 11 月 8 日
I have imported pytorch by this method! Thank you so much!
Pooria Tabesh Mehr
Pooria Tabesh Mehr 2022 年 9 月 5 日
Hi,
I have same problem, howver this solution doesn't work for me.I have searched a lot, but I couldn't solve the eporoblem. Could you please give me another solution if you know?

サインインしてコメントする。

その他の回答 (1 件)

Navid Hashemi
Navid Hashemi 2023 年 2 月 23 日
I am also facing this error when I run a python script which imports torch using the MATLAB function pyrunfile()
Error using __init__><module> (line 135)
Python Error: OSError: [WinError 126] The specified module could not be found. Error loading
"C:\Users\Navid\.conda\envs\RL37\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by