Main Content

Install MATLAB Engine API for Python

To start the MATLAB® engine within a Python® session, you first must install the engine API as a Python package. For other requirements, see System Requirements for MATLAB Engine API for Python.

Verify Your Configuration

Before you install, verify your Python and MATLAB configurations.

  • Check that your system has a supported version of Python and MATLAB R2014b or later. For more information, see Versions of Python Compatible with MATLAB Products by Release.

  • To check that Python is installed on your system, run Python at the operating system prompt. Make sure that the Python path is included in your system path environment variable.

  • Add the folder that contains the Python interpreter to your path, if it is not already there.

Install Engine API

You can install MATLAB Engine API for Python using the pip command or a Python setup script

Install Using pip

Starting with MATLAB R2022b, you can use the pip command to install the API. Choose one of the following procedures and execute from the system prompt.

  • To install from the MATLAB folder, on Windows® type:

    cd "matlabroot\extern\engines\python"
    python -m pip install .
  • Install the engine API from with the command:

    python -m pip install matlabengine

Install Using

MATLAB provides a standard Python file for building and installing the engine using Python setuptools. For platform-specific commands, see Python Setup Script to Install MATLAB Engine API.

Start MATLAB Engine

Start Python. Type these commands from the Python prompt to import the MATLAB module and start the engine:

import matlab.engine
eng = matlab.engine.start_matlab()

For more information, see Start and Stop MATLAB Engine for Python.

Troubleshooting MATLAB Engine API for Python Installation

  • Make sure that your MATLAB release supports your Python version. See Versions of Python Compatible with MATLAB Products by Release.

  • Make sure that you have sufficient privileges to execute the install command from the operating system prompt. On Windows, if necessary, open the command prompt with the Run as administrator option.

  • You must run the Python install command from the specified MATLAB folder. For detailed instructions, choose one of the platform links in Install Engine API.

    python install
  • The installer installs the engine in the default Python folder. To use a nondefault location, see Install MATLAB Engine API for Python in Nondefault Locations.

  • If you installed the package in a nondefault folder using --prefix, make sure to set the PYTHONPATH environment variable. For example, suppose that you used this installation command:

    python install --prefix="matlab22aPy39"

    In Python, update PYTHONPATH with this command:

  • For more troubleshooting information, see Troubleshoot MATLAB Errors in Python.

Related Topics