Call User made Python modlue from Matlab

1 vue (au cours des 30 derniers jours)
giacomo labbri
giacomo labbri le 24 Déc 2020
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!

Réponse acceptée

Rishik Ramena
Rishik Ramena le 28 Déc 2020
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.

Plus de réponses (0)

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by