can't run a python function from matlab

2 ビュー (過去 30 日間)
Kfir Weissman
Kfir Weissman 2021 年 12 月 23 日
コメント済み: Kfir Weissman 2024 年 12 月 20 日
hi, i try to run my order_files.py file.
i already add my venv from anaconda to matlab and when i run "pyenv" in matlab its
found it.
the problem is when i run the function "hel" in the order_files.py file from matlab i get this error:
"Unable to resolve the name py.order_files.hel."
what can i do about that?
  2 件のコメント
Anushka Perera
Anushka Perera 2021 年 12 月 23 日
Did you add the current folder to the Python search path? Something like this:
if count(py.sys.path,'') == 0
insert(py.sys.path,int32(0),'');
end
Kfir Weissman
Kfir Weissman 2021 年 12 月 23 日
Which folder?

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

採用された回答

Meet
Meet 2024 年 12 月 20 日
Hi Kfir,
You could try these steps to troubleshoot the issue:
  1. Ensure that the Python environment set in MATLAB "pyenv" is correctly pointing to your Anaconda environment. You can check this by running.
>> pyenv
2. Ensure that the directory containing file "order_files.py" is in the Python path.
if count(py.sys.path, 'directory_containing_pyFile') == 0
insert(py.sys.path, int32(0), 'directory_containing_pyFile');
end
3. Try restarting MATLAB and execute the command "py.order_files.hel()" again.
I hope this resolves the issue!!
  1 件のコメント
Kfir Weissman
Kfir Weissman 2024 年 12 月 20 日

Hi thanks for answering, i did resolve this issue almost 4 years ago😅 It took some time to connect matlab and python, from matlab2022b (after i finish my project) python function executable from matlab using a single builtin command.. thanks for answering anyway!!😊

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by