Install MATLAB Engine API for Python
MATLAB® Engine API for Python® allows you to call MATLAB functions and execute MATLAB commands from within a Python environment. To use the MATLAB engine, you must have a supported version of Python installed on your machine, and you must install MATLAB Engine API for Python as a Python package.
Verify Your Configuration and Install Python
If you have Python installed, verify that you are using a version that is supported by
the MATLAB engine. You can check which version of Python you have installed on a Windows® system by entering python -V at your operating
system prompt. On Linux® or macOS systems, use python3 -V instead. Then determine if
your Python version is compatible with your MATLAB release by checking the Versions of Python Compatible with MATLAB Products by Release
page.
In addition, verify that you are using a 64-bit version of Python. A 64-bit version of Python is necessary to match the architecture of MATLAB. To test whether your version of Python is 32-bit or 64-bit, enter this code at the Python prompt. This code returns True if the version is
64-bit and False if the version is 32-bit.
import sys
print(sys.maxsize > 2**32)If you do not have Python installed or need a different version, see Configure Your System to Use Python.
Install MATLAB Engine API for Python
MATLAB provides various methods for installing MATLAB Engine API for Python. You also can use a preinstalled version of the MATLAB Engine API for Python that ships with MATLAB. (since R2026a)
Install from MATLAB
You can install the MATLAB engine directly from MATLAB. Start MATLAB and run the following commands.
| System | MATLAB Commands |
|---|---|
Windows |
cd (fullfile(matlabroot,"extern","engines","python")) system("python -m pip install .") |
Linux and macOS |
cd (fullfile(matlabroot,"extern","engines","python")) system("python3 -m pip install .") |
Install from Operating System
Alternatively, you can install the MATLAB engine from the operating system prompt. First, you need the path
to the MATLAB Engine API for Python folder. To locate this folder, start MATLAB and enter matlabroot in the Command Window.
Then replace matlabroot in
the following commands with the path value that MATLAB returned.
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.
| System | System Commands |
|---|---|
Windows |
cd "matlabroot\extern\engines\python"
python -m pip install .
|
Linux and macOS |
cd "matlabroot/extern/engines/python"
python3 -m pip install .
|
Install from Python Package Index
Alternatively, you can install the MATLAB engine from the Python Package Index (PyPI). Unlike the other install options, you do not need to navigate to the MATLAB Engine API for Python folder first.
To install the latest version of the MATLAB engine available from PyPI, run this command from your operating system prompt:
python -m pip install matlabengine
The latest MATLAB engine version is compatible only with the most recent MATLAB release (currently R2026a). It is not compatible with prerelease versions of MATLAB.
If you do not have the latest release of MATLAB, specify a version of the MATLAB engine that is compatible with your release. Run this command from
your operating system prompt, where
is the MATLAB engine version.n.n.n
python -m pip install matlabengine==n.n.n
To determine which version is compatible with your MATLAB release:
Go to the PyPI release history page for MATLAB Engine API for Python.
Open each MATLAB engine release page, and compare the MATLAB release shown under Required MathWorks Products with your MATLAB release until you find a match.
You can then replace
with the MATLAB engine version shown on the matching page.n.n.n
PyPI installs the MATLAB engine into the default package folder for the Python interpreter that was used to call the MATLAB engine installer. To install the engine in a nondefault folder,
run this command from your operating system prompt, where
is the folder
to install in.installdir
python -m pip install --target installdir matlabengine
To include on the
search path for Python packages,
add installdir to
the installdirPYTHONPATH environment variable.
Use Preinstalled Version of MATLAB Engine API for Python
Since R2026a
MATLAB includes a preinstalled version of the MATLAB Engine API for Python. This preinstalled version of the engine is located in the
folder, where matlabroot/extern/engines/python/dist is the
folder displayed when you run matlabrootmatlabroot in the Command
Window.
To use the preinstalled version of the MATLAB engine, add the
folder to the matlabroot/extern/engines/python/distPYTHONPATH environment variable. Alternatively,
you can insert it into Python's sys.path prior to importing
the engine.
Install in Virtual Environment
You can install MATLAB Engine API for Python in a virtual environment. For detailed instructions on installing MATLAB Engine API for Python in a virtual environment, see the MATLAB Answers™ article Use the MATLAB Engine API for Python with a Virtual Environment. For information about virtual Python environments, see the Python tutorial Virtual Environments and Packages. You must activate the virtual environment before running the installation commands.
Start MATLAB Engine in Python
To import the MATLAB Engine API for Python package and start the MATLAB engine, run these commands from the Python prompt.
import matlab.engine
eng = matlab.engine.start_matlab()
For more information, see Start and Stop MATLAB Engine for Python.