How to trace an error "Unable to resolve the name" when running python from matlab

조회 수: 19 (최근 30일)
Hello!
I am trying to run an external python library from Matlab. I repeated Matlab example with speech recognition (sentiment analysis) and everything works fine. But when I am trying to run my own script with exactly the same structure, I an getting an error "Unable to resolve the name py.radisCall.load_sp2matlab."
I am using python 3.7.2 and Matlab R2020a. The only reason I can imagine for this error is the load_spec function loads an object of custom class described in radis library. But why Matlab unable to resolve the name? Or how to trace this error further?
Python function:
import radis as rad
def load_sp2matlab(filename):
spec = rad.load_spec(filename)
return spec
Matlab function:
spec_file = 'D:/Blekhshtein_phd/Matlab/welcome.spec';
pyenv
radis_call_path = fileparts(which('radisCall.py'));
if count(py.sys.path, radis_call_path) == 0
insert(py.sys.path, int32(0), radis_call_path);
end
try
py_spec = py.radisCall.load_sp2matlab(spec_file);
catch e
end
Thank you in advance!

답변 (1개)

Srija Kethiri
Srija Kethiri 2022년 8월 22일
Hi Maksim,
The reason for the error could be the module doesn’t exist in the path.
Please check the python path and make sure that it contains an absolute path to the directory where your Python module is saved. To check the Python path, please use the following command,
py.sys.path
If the directory where the custom Python module is located is not added in the Python path, then please navigate to the directory where the custom Python module is defined and add it to Python path using the following command,
py.importlib.import _module('magpyHelper')
In case the later custom Python module is still not found, then the later command will provide with a more comprehensive reason about why the module could not be imported.
You can read up more about it in the following documentation page:
Hope this helps!

카테고리

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