How to trace an error "Unable to resolve the name" when running python from matlab
6 次查看(过去 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!
0 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!