필터 지우기
필터 지우기

Why do I receive an error "Unable to resolve the name py.(moduleName)" when using the Python interface in MATLAB?

조회 수: 35 (최근 30일)
When trying to use a python module in MATLAB using the Python interface, I receive the following error message,
Unable to resolve the name py.(moduleName)
Why do I receive an error "Unable to resolve the name py.(moduleName)" when using the Python interface in MATLAB?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2024년 8월 7일
편집: MathWorks Support Team 2024년 8월 7일
1) If moduleName is a built-in or third-party Python module, then check if this module has already been installed in your Python distribution before importing it. You can check this by executing the following command in a Windows/Unix terminal.
python -m pip list
Install moduleName, if it is not listed. For example, from a Windows/Unix terminal.
python -m pip install moduleName
2) If moduleName is a user-defined module, please check the Python path and make sure that it contains an absolute path to the directory where this user-defined Python module is saved. To check the Python path, please use the following command in MATLAB.
py.sys.path
If the directory where the user-defined tom Python module is located is not included in the Python path, then add the directory to the Python path in MATLAB with the following command.
insert(py.sys.path,int32(0),"<absolute path to module directory>")
See this documentation for more information about calling user-defined modules.
 
3) In case the user-defined Python module is still not found, then try executing this command from MATLAB.
py.importlib.import_module('moduleName')
The error message for this command may provide a more comprehensive reason about why the module could not be imported.
4) See
for more comprehensive coverage of this issue.

추가 답변 (0개)

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by