Why can't I run my python script from Matlab?

조회 수: 7 (최근 30일)
Stelios Fanourakis
Stelios Fanourakis 2019년 5월 13일
편집: Rafael Rebouças 2021년 1월 19일
Hi
I am trying to use this line
py.intervals.py();
Where intervals is a python script. I get the error
>> py.intervals.py()
Undefined variable "py" or class "py.intervals.py".
I am using R2018b. Do I need to purchase a Python Libraries API?

답변 (3개)

Jan
Jan 2019년 5월 17일
  댓글 수: 1
Stelios Fanourakis
Stelios Fanourakis 2019년 5월 19일
Yes I have seen the Python Libraries. I got the errors
Import argument 'intervals.py' cannot be found or cannot be imported.

댓글을 달려면 로그인하십시오.


Prathamesh Degwekar
Prathamesh Degwekar 2019년 5월 21일
Hi,
I see two possible corrections you could try. Firstly try calling the python module itself instead of the file name (like "py.mymod.search(N)" instead of "py.mymod.py").
Secondly, maybe your file isn't in the python search path. If it isn't, try adding your folder to the python sys path using:
if count(py.sys.path,'') == 0
insert(py.sys.path,int32(0),'');
end

Rafael Rebouças
Rafael Rebouças 2021년 1월 19일
편집: Rafael Rebouças 2021년 1월 19일
My solution:
% Simple way to load your library
copyfile(my_library_file_path, pwd, 'f');
% It's necessary to load library
py.my_library.any_method_or_function();
delete 'my_library.py';
Now, your Python library is loaded to use in any directory.

카테고리

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