필터 지우기
필터 지우기

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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by