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. MATLAB provides a standard Python setup.py file for building and installing the engine using the distutils module. You can use the same setup.py commands to build and install the engine on Windows®, Mac, or Linux® systems.

Before you install, verify your Python and MATLAB configurations.

  • Check that your system has a supported version of Python and MATLAB R2014b or later. To check that Python is installed on your system, run Python at the operating system prompt.

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

  • Find the path to the MATLAB folder. Start MATLAB and type matlabroot in the command window. Copy the path returned by matlabroot.

To install the engine API, choose one of the following.

  • At a Windows operating system prompt —

    cd "matlabroot\extern\engines\python"
    python setup.py install
    

    You might need administrator privileges to execute these commands.

  • At a macOS or Linux operating system prompt —

    cd "matlabroot/extern/engines/python"
    python setup.py install
    

    You might need administrator privileges to execute these commands.

  • At the MATLAB command prompt —

    cd (fullfile(matlabroot,'extern','engines','python'))
    system('python setup.py install')
  • Use one of the nondefault options described in Install MATLAB Engine API for Python in Nondefault Locations.

Note

You must call this python command in the specified folder.

Start Python, import the module, and start the MATLAB engine:

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

Related Topics

External Websites