Contenu principal

Appeler Python à partir de MATLAB

Appeler directement les fonctionnalités Python® depuis MATLAB®

Vous pouvez accéder aux bibliothèques Python directement depuis MATLAB en ajoutant le préfixe py. au nom Python. Consultez Access Python Modules from MATLAB - Getting Started. Par exemple :

py.list({'This','is a','list'})      % Call built-in function list
py.textwrap.wrap('This is a string') % Call wrap function in module textwrap
Vous pouvez exécuter des instructions Python dans l’interpréteur Python directement depuis MATLAB avec les fonctions pyrun ou pyrunfile. Par exemple :
pyrun("l = ['A','new','list']")  % Call list in Python interpreter
Pour plus d’informations, consultez Directly Call Python Functionality from MATLAB.

Si au lieu de cela vous souhaitez appeler des fonctions MATLAB depuis des applications Python, consultez Appeler MATLAB à partir de Python pour plus d’informations.

Fonctions

développer tout

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

Tâches du Live Editor

Run Python Code (Exécuter du code Python)Run Python statements or script files in the Live Editor (depuis R2024a)

Rubriques

Utiliser des bibliothèques Python dans MATLAB

Exécuter du code Python depuis MATLAB

Transmettre des données

Résolution des problèmes

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.

Sélection d՚exemples