Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to call Python code using Matlab #13536

Open
Saswati-Project opened this issue Jun 20, 2024 · 1 comment
Open

Fail to call Python code using Matlab #13536

Saswati-Project opened this issue Jun 20, 2024 · 1 comment

Comments

@Saswati-Project
Copy link

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
@Siddharth-Latthe-07
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants