Main Content

Aufrufen von Python aus MATLAB heraus

Direktaufruf von Python®-Funktionen aus MATLAB® heraus

Sie können auf Python-Bibliotheken direkt aus MATLAB heraus zugreifen, indem Sie das Präfix py. vor den Python-Namen setzen. Siehe Access Python Modules from MATLAB - Getting Started. Beispiel:

py.list({'This','is a','list'})      % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrap
Sie können Python-Anweisungen im Python Interpreter direkt aus MATLAB heraus ausführen. Verwenden Sie dazu die Funktion pyrun oder pyrunfile. Beispiel:
pyrun("l = ['A','new','list']")  % Call list in Python interpreter
Weitere Informationen finden Sie unter Directly Call Python Functionality from MATLAB.

Weitere Informationen dazu, wie Sie stattdessen MATLAB-Funktionen aus Python Anwendungen heraus aufrufen, erhalten Sie unter Aufrufen von MATLAB aus Python heraus.

Funktionen

alle erweitern

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

Live Editor Tasks

Ausführen von Python-CodeRun Python statements or script files in the Live Editor (Seit R2024a)

Themen

Nutzung von Python-Bibliotheken in MATLAB

Ausführen von Python-Code aus MATLAB heraus

Weitergabe von Daten

Fehlersuche

Determine if Error is Python or MATLAB Error

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

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.