Contenido principal

La traducción de esta página aún no se ha actualizado a la versión más reciente. Haga clic aquí para ver la última versión en inglés.

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 Llamar directamente a funcionalidades de Python desde 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

pyenvCambiar el entorno predeterminado del intérprete de Python
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

Determine if an error originates in Python or MATLAB code.

Unable to resolve the name py.myfunc

Troubleshoot failures loading Python.

Limitations to Python Support

Some Python features are not currently 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

Errors might be caused by an input array with more than one dimension whose size is greater than 1.

Error Converting Elements of list or tuple

Use string and numeric converters for list and tuple types.

Ejemplos destacados