フィルターのクリア

Call User made Python modlue from Matlab

1 回表示 (過去 30 日間)
giacomo labbri
giacomo labbri 2020 年 12 月 24 日
コメント済み: giacomo labbri 2021 年 1 月 1 日
Hi,
I am having trouble calling a python module (wirtten by me) from matlab. I saw simarl questions and aswer but no onw I found was useful to be. Here are the details:
I have installed Python 3.8 on Windows via the official python website.
In matlab I set the path to the python executable using pyenv:
py = pyenv('Version', 'C:\Users\giaco\AppData\Local\Programs\Python\Python38\python.exe');
Since my module is in another folder I add this folder to the python search path using the function py_addpath (found on the matlab file exchange)
py_paths=py_addpath('C:\Users\giaco\Documents\PROJ_WORK_Thesis\');
The path seems to be added correctly infact py_paths is:
py_paths =
7×1 cell array
{0×0 char }
{'C:\Users\giaco\Documents\PROJ_WORK_Thesis' }
{'C:\Users\giaco\AppData\Local\Programs\Python\Python38\python38.zip' }
{'C:\Users\giaco\AppData\Local\Programs\Python\Python38\DLLs' }
{'C:\Users\giaco\AppData\Local\Programs\Python\Python38\lib' }
{'C:\Users\giaco\AppData\Local\Programs\Python\Python38' }
{'C:\Users\giaco\AppData\Local\Programs\Python\Python38\lib\site-packages'}
But when I run my module as:
the=py.thetae.thetae(r.pa, r.ta, r.rh);
I get the following error:
Unable to resolve the name py.thetae.thetae.
Any suggestion on how to solve this?
Thanks in advance!

採用された回答

Rishik Ramena
Rishik Ramena 2020 年 12 月 28 日
Try adding adding the path as:
insert(py.sys.path,int32(0),'C:\Users\giaco\Documents\PROJ_WORK_Thesis\');
Please verify the following points as well
  1. A file called thetae.py exists in your 'C:\Users\giaco\Documents\PROJ_WORK_Thesis\' directory.
  2. The file if exists has the function thetae defined in it.
  1 件のコメント
giacomo labbri
giacomo labbri 2021 年 1 月 1 日
It worked! Thanks

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

その他の回答 (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