To call Python® modules in MATLAB®, you must have a supported version of the reference implementation (CPython) installed on your system. MATLAB supports versions 2.7, 3.6, and 3.7.
To determine if your system has a supported version, use the pyenv
function.
The value set by pyenv
is persistent across MATLAB sessions. If you have multiple supported versions, use
pyenv
to display the default version used by MATLAB.
You cannot switch between versions of Python in a single MATLAB session. MATLAB automatically selects and loads a Python version when you type a Python command, such as:
py.funcname
If you want to change versions, restart MATLAB and then run pyenv
with the new version
information.
On Windows® platforms, use either:
pyenv('Version','version')
or
pyenv('Version','executable')
If you downloaded a Python interpreter, but did not register it in the Windows registry, use:
pyenv('Version','executable')
To set the version, type:
pyenv('Version','executable')
where executable
is the full path
to the Python executable file.
The architecture of Python must match the architecture of MATLAB. For more information, see Install Supported Python Implementation.
On Linux® and Mac systems, if you build the Python executable,
configure the build with the --enable-shared
option.