Open Saswati-Project opened 4 months ago
@Saswati-Project The error you're encountering is indicative of a binary incompatibility between NumPy and another library, likely one that spaCy depends on, such as Thinc. This can occur when libraries are compiled against different versions of NumPy or when there are mismatched versions of the libraries. You might try these steps and let me know, if it works,
pyenv('Version', 'C:\Users\cse_s\AppData\Local\Programs\Python\Python312\python.exe');
import spacy
def test_spacy_function(): nlp = spacy.load("en_core_weblg") doc = nlp("This is a sentence.") return [(token.text, token.pos) for token in doc]
4. After confirming the Python script works independently, call it from MATLAB:-
a. Set the Python environment in MATLAB
pyenv('Version', 'C:\Users\cse_s\AppData\Local\Programs\Python\Python312\python.exe');
b. ensure correct path:-
path_add = fileparts(which('test_spacy.py')); if count(py.sys.path, path_add) == 0 insert(py.sys.path, int64(0), path_add); end
finally, import and call the fucntion:-
py.importlib.import_module('test_spacy'); result = py.test_spacy.test_spacy_function(); disp(result)
spaCy version 3.7.5
Location C:\Users\cse_s\AppData\Local\Programs\Python\Python312\Lib\site-packages\spacy
Platform Windows-11
Python version 3.12.3
Pipelines en_core_web_lg (3.7.1)
I want to call the Spacy code using Matlab. The Spacy code is as follows which work well using Pycharm IDE.
However, the Matlab code throws errors
The Matlab code is
test_spacy is the python file name that I have. How can I solve this issue?