Call User made Python modlue from Matlab

1 visualización (últimos 30 días)
giacomo labbri
giacomo labbri el 24 de Dic. de 2020
Comentada: giacomo labbri el 1 de En. de 2021
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!

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by