Python Module not found when call the python function using Matlab
I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels);I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels); I want to call a python function using Matlab. I am working on the NLP project, particularly text recognization. The name of the python file that I want to call using the Matlab is final_output.py. The final_output.py contains a import statement import spacy. This script run well when I run it using Pycharm. I installed all the required library using PyCharm terminal.
However, when I call the same python file from Matlab I received an error,
Error using final_output><module>
Python Error: ModuleNotFoundError: No module named ‘spacy’
Error in <frozen importlib>_call_with_frames_removed (line 228)
Error in <frozen importlib>exec_module (line 850)
Error in <frozen importlib>_load_unlocked (line 680)
Any help will be appreciated.
The Matlab code is as follows
pe = pyenv;
disp(pe);
py.importlib.import_module(‘final_output’)
% Add the directory containing the Python script to the Python path
path_add = fileparts(which(‘final_output.py’));
if count(py.sys.path, path_add) == 0
insert(py.sys.path, int64(0), path_add);
end
% Define model path and text to process
model_path = ‘D:\output\model-best’;
text = ‘Roses are Red’;
% Call the Python function
pyOut = py.final_output.text_recognizer(model_path, text);
% Convert the output to a MATLAB cell array
entity_labels = cell(pyOut);
disp(entity_labels); matlab, python MATLAB Answers — New Questions