Call User made Python modlue from Matlab

1 visualizzazione (ultimi 30 giorni)
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!

Risposta accettata

Rishik Ramena
Rishik Ramena il 28 Dic 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.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by