Python scripts with numpy don't work when called from MATLAB
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm trying to call a python script I've written, from within my MATLAB code. I'm having a problem where I can't call any scripts that import numpy.
For example, the following file (abc.py) works without any issues:
def foo():
return 55
but if I add the import statement, it ceases to work.
import numpy as np
def foo():
return 55
The MATLAB error I get is
Undefined variable "py" or class "py.abc.foo".
Does anyone have any idea on how to fix this? I'm running the latest version of Anaconda for my python.
0 comentarios
Respuestas (1)
surya venu
el 19 de Jul. de 2024
Hi,
The issue you're encountering is likely due to MATLAB not being able to locate the correct Python environment where "numpy" is installed. Here are some steps you can follow to resolve this issue:
1) Verify Python Environment in MATLAB: Ensure that MATLAB is using the correct Python environment. You can do this by setting the Python environment in MATLAB using the "pyenv" function.
pyenv('Version', 'path_to_your_python_executable');
2) Check if "numpy" is Installed: Ensure that "numpy" is installed in the Python environment that MATLAB is using. If numpy is not installed, you can install it using:
conda install numpy
3) Restart MATLAB: After setting the Python environment and ensuring "numpy" is installed, restart MATLAB to make sure the changes take effect.
By following these steps, MATLAB should be able to locate and use the correct Python environment with numpy installed.
Hope it helps.
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!