Contenido principal

Llamar a Python desde MATLAB

Llame directamente a las funciones de Python® desde MATLAB®

Puede acceder a las bibliotecas de Python directamente desde MATLAB agregando el prefijo py. al nombre Python. Consulte Acceder a módulos de Python desde MATLAB: introducción. Por ejemplo:

py.list({'This','is a','list'})      % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrap
Puede ejecutar instrucciones de Python en el intérprete de Python directamente desde MATLAB usando las funciones pyrun o pyrunfile. Por ejemplo:
pyrun("l = ['A','new','list']")  % Call list in Python interpreter
Para obtener más información, consulte Directly Call Python Functionality from MATLAB.

Si en su lugar desea llamar a las funciones de MATLAB desde las aplicaciones de Python, consulte Llamar a MATLAB desde Python para obtener más información.

Funciones

expandir todo

pyenvChange default environment of Python interpreter
PythonEnvironmentPython environment information
pyrunRun Python statements from MATLAB (Desde R2021b)
pyrunfileRun Python script file from MATLAB (Desde R2021b)
pyargsCreate keyword arguments for Python function
matlab.exception.PyExceptionCapture error information for Python exception

Tareas de Live Editor

Ejecutar código de PythonRun Python statements or script files in the Live Editor (Desde R2024a)

Temas

Usar bibliotecas de Python en MATLAB

Ejecutar código de Python desde MATLAB

Paso de datos

Solución de problemas

Determine if Error is Python or MATLAB Error

Tips to determine if an error originates in Python or MATLAB code.

Unable to resolve the name py.myfunc

Troubleshooting failures loading Python.

Limitations to Python Support

Python features not supported in MATLAB.

Handle Python Exceptions

MATLAB catches exceptions thrown by Python and converts them into a matlab.exception.PyException object.

Troubleshooting Matrix and Numeric Argument Errors

Error might be caused by input array with more than one non-singleton dimension.

Error Converting Elements of list or tuple

How to use string and numeric converters for list and tuple types.

Ejemplos destacados