Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Getting Started with Python

Examples and concepts to help you quickly get started using Python® in MATLAB®

To call Python libraries from MATLAB, you need to install a supported version of the reference implementation (CPython) for Python. MATLAB supports versions 2.7, 3.3, 3.4, and 3.5. The version you install depends on the libraries you are using. For information, see Install Supported Python Implementation

For help on the Python language, see www.python.org/doc. For help on third-party or user-defined modules, refer to the product documentation.

To call MATLAB functions from Python applications, see MATLAB Engine API for Python.

Functions

pyversion Change default version of Python interpreter
pyargs Create keyword argument for Python function

Classes

matlab.exception.PyException Capture error information for Python exception

Topics

System and Configuration Requirements

How to verify you have installed a supported version of Python.

Create a Python Object

Different behaviors between MATLAB variables and Python objects.

Help for Python Functions

How to find help for Python functions.

Python import and MATLAB import Commands

How to use Python import and MATLAB import commands.

Call User-Defined Python Module

Create a Python module used by examples in this documentation.

Reload Modified User-Defined Python Module

This example shows how to reload a modified Python module.

Install Supported Python Implementation

How to install a supported version of Python from the www.python.org website.

Troubleshooting

Limitations to Python Support

Python features not supported in MATLAB.

Undefined variable "py" or function "py.command"

Troubleshooting failures loading Python.

Unsupported MATLAB Types

MATLAB types that are not supported in Python.

Using Python Data in MATLAB

MATLAB automatically converts compatible Python data to MATLAB data. For Python types that do not have compatible MATLAB types, MATLAB provides functions to convert Python data types to MATLAB types manually.

Limitations to Indexing into Python Objects

You can access data in Python container objects, like lists and dictionaries, with index values, similar to referencing an element in a MATLAB matrix. There are, however, ways to index into matrices which are not supported for these Python types.

Handle Python Exceptions

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

Troubleshooting Error Messages

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

Was this topic helpful?