Installation - Python based Interfaces
Important
This installation step is only required when wanting to work with the fluent mlflow interface in MATLAB and/or the MATLAB flavor. It is not necessary to perform these steps when you only want to work with the RESTful interface to mlflow.
Note
When working with this mlflow package as part of another MathWorks Product Support Package like “MATLAB Interface for Databricks” or “MATLAB Interface for Azure Machine Learning” then under certain circumstances, your environment may already have been pre-configured with Python and the mlflow package, in which case these steps do not have to be repeated. This is for example true when working with “MATLAB as Custom Application on AzureML”.
Requirements
Python 3.10 (or newer) environment with:
mlflow
matlab-mlflow (this package)
onnx (if working with ONNX sub flavor)
Python Environment
A requirements.txt and pyproject.toml are included inside the Software/Python directory which can help with setting up such a Python (virtual) environment with the correct tools. Instructions are included below on how to setup the environment using Python Virtual Environment (venv) or alternatively using uv. You are of course also free to setup this environment in any other way you like (conda, virtualenv, system package manager, etc.)
uv
Apart from managing virtual environments and Python packages, uv can also manage Python versions itself and create virtual environments with/for specific Python versions. For most uv commands a -p <version> option can be added, e.g. -p 3.10 or -p 3.12 to target Python version 3.10 or 3.12 respectively. In the examples below -p 3.10 is used but this can be changed. Make sure to choose a Python version which is compatible with the MATLAB release(s) you want to work with, see:
https://www.mathworks.com/support/requirements/python-compatibility.html
Linux
To create a virtual environment .venv inside the Software/Python directory with the correct packages for the project using uv, use:
$ cd Software/Python
$ uv sync -p 3.10
Windows
To create a virtual environment .venv inside the Software/Python directory with the correct packages for the project using uv, use:
c:\work\matlab-mlflow> cd Software\Python
c:\work\matlab-mlflow\Software\Python> uv sync -p 3.10
Python Virtual Environment venv
When working with Python standard venv module to create a virtual environment you first need to install a particular Python (with venv module) version and then you create the virtual environment using that Python version. Make sure to install a Python version that is compatible with the MATLAB version(s) you want to work with, see:
https://www.mathworks.com/support/requirements/python-compatibility.html
On Linux you will typically install Python using your system package manager, on Windows you typically download an installer from https://python.org. If your Linux distro version does not have a standard package for the Python version you want/need or if you cannot find a Windows installer for the right version, consider using a tool like uv which can also download and manage Python versions for you.
Linux
To create a virtual environment .venv inside the Software/Python directory, use:
$ cd Software/Python
$ python3.10 -m venv .venv
Note
We explicitly call python3.10 here and not just python to ensure we indeed create a virtual environment for that Python version specifically and not using any other Python version which may have been on PATH.
And then install the required packages by activating the environment:
$ source .venv/bin/activate
and then using pip:
$ pip install -r requirements.txt
Windows
To create a virtual environment .venv inside the Software/Python directory, use:
c:\work\matlab-mlflow> cd Software\Python
c:\work\matlab-mlflow\Software\Python> %LOCALAPPDATA%\Programs\Python\Python310\python.exe -m venv .venv
Assuming CPython 3.10 has been installed in its default (user-based) location. If it (or a different version) has been installed elsewhere, replace the path
%LOCALAPPDATA%\Programs\Python\Python310as appropriate.
And then install the required packages by activating the environment:
c:\work\matlab-mlflow\Software\Python> .venv\Scripts\activate
and then using pip:
c:\work\matlab-mlflow\Software\Python> pip install -r requirements.txt
MATLAB Configuration
To add the relevant MATLAB code to your MATLABPATH inside MATLAB, use startup.m from the Software/MATLAB directory:
% For example, cd to the right directory and run startup
>> cd Software/MATLAB
>> startup
% Or for example use run with the absolute path of the script
>> run('/work/matlab-mlflow/Software/MATLAB/startup.m')
Further, to configure MATLAB’s Python Interface to work with the (virtual) environment which contains the required Python packages, use the pyenv function:
% For example on Linux
>> pyenv('Version','/work/matlab-mlflow/Software/Python/.venv/bin/python')
% Or on Windows
>> pyenv('Version','c:\work\matlab-mlflow\Software\Python\.venv\Scripts/pythonw.exe')
This is a persistent setting and does not have to be repeated every MATLAB session.
MLflow Tracking servers
Both the Fluent interface and the MATLAB MLflow flavor support working with MLflow (compatible[1]) Tracking servers. This is supported in the same way as in other Python MLflow packages, see:
So that is by either setting environment variable MLFLOW_TRACKING_URI before using the package or by explicitly calling mlflow.set_tracking_uri in your MATLAB code.
Hint
In some environments MLFLOW_TRACKING_URI may have been automatically set for you. E.g. if you are working on AzureML Compute Instances, Microsoft will automatically set it to point the Model storage of your AzureML Workspace.
Self-signed HTTPS servers
If you are working with a server accessed over HTTPS and the server is using a self-signed certificate you can set environment variable MLFLOW_TRACKING_SERVER_CERT_PATH and point it to the (PEM encoded) certificate of the server to allow the MATLAB Fluent interface to work with it.
Note
This must be set before interacting with any of the functionality in the Fluent- or MATLAB flavor interfaces. Setting the variable after the interfaces have already been used in a MATLAB session will have no effect. Restart MATLAB as appropriate.
Server authentication
If your server requires username/password or token authentication, configure environment variables MLFLOW_TRACKING_USERNAME and MLFLOW_TRACKING_PASSWORD, or MLFLOW_TRACKING_TOKEN respectively.
If your server requires a custom authentication plugin, install the plugin in the Python environment as used by MATLAB and provide any further configurations as documented in the plugin documentation.