How to solve "MATLAB cannot determine whether "py" refers to a function or variable" under SPMD.

2 ビュー (過去 30 日間)
Minjeong
Minjeong 2019 年 11 月 8 日
回答済み: Shrinidhi KR 2020 年 5 月 8 日
Good day!
I need to use "py" function to call python module in MATLAB.
It worked until I used "py" command inside the body of an SPMD statment.
I got an error messege: MATLAB cannot determine whether "py" refers to a function or variable.
How can I solve this problem and be able to call python module even in the body of an SPMD statement?
Sincerely,
Minjeong

回答 (1 件)

Shrinidhi KR
Shrinidhi KR 2020 年 5 月 8 日
Verfiy that none of these points mentioned in this link is causing the issue.
I tried to use "py" command inside spmd statement in this way and it worked fine. To make sure the python module is in the path
P = py.sys.path;
if count(P,'path of your python module') == 0
insert(P,int32(0),'path of your python module');
end
spmd
N = py.list({'Jones','Johnson','James'});
py.mymod.search(N)
end
This is the python script
# mymod.py
"""Python module demonstrates passing MATLAB types to Python functions"""
def search(words):
"""Return list of words containing 'son'"""
newlist = [w for w in words if 'son' in w]
return newlist

カテゴリ

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