spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Fail to call Python code using Matlab

Open Saswati-Project opened this issue 1 year ago • 1 comments

How to reproduce the behaviour

Python code: File name: test_spacy.py

import spacy
nlp = spacy.load("en_core_web_lg")
doc = nlp("This is a sentence.")

No error while run the python code using Pycharm IDE. Matlab code for calling the python code

pyenv;
py.importlib.import_module('test_spacy');
path_add = fileparts(which('test_spacy.py'));
if count(py.sys.path, path_add) == 0
    insert(py.sys.path, int64(0), path_add);
end

Error occurred while run the Matlab code: Error using numpy_ops>init thinc.backends.numpy_ops Python Error: ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

Matlab and python codes all are in the same folder. Created a python project using PyCharm. Then crated the Matlab file and saved the file in the Python project file

Your Environment

  • Operating System: Windows 11
  • Python Version Used: 3.12.3
  • spaCy Version Used: 3.7.5
  • Environment Information: C:\Users\cse_s\AppData\Local\Programs\Python\Python312\Lib\site-packages\spacy

Saswati-Project avatar Jun 20 '24 16:06 Saswati-Project

@Saswati-Project The error you are encountering is a common issue that arises due to a version mismatch between different Python libraries, particularly NumPy and libraries that depend on it, such as spaCy. You may try these steps and check whether the issue is solved or not?

  1. Verify the Python Environment in MATLAB:- check it through: -
pyenv
  1. Make sure this environment matches the one used in PyCharm. If not, you can set the Python environment in MATLAB using-
pyenv('Version', 'path_to_your_python_executable');
  1. lastly upgrade all the dependencies and re-run the matlab code

Let me know, if it is working Thanks

Siddharth-Latthe-07 avatar Jun 27 '24 12:06 Siddharth-Latthe-07