Last modified: Apr 03, 2025 By Alexander Williams
How to Install MLflow in Python Step by Step
MLflow is a powerful tool for managing machine learning workflows. It helps track experiments, package code, and deploy models. This guide will walk you through installing MLflow in Python.
Table Of Contents
Prerequisites
Before installing MLflow, ensure you have Python installed. You can check this by running:
python --version
Python 3.8.5
If you don't have Python, download it from the official website. Also, ensure pip is installed. Pip is Python's package installer.
Install MLflow Using Pip
The easiest way to install MLflow is using pip. Open your terminal or command prompt and run:
pip install mlflow
Successfully installed mlflow-1.30.0
This command installs the latest version of MLflow. If you encounter a ModuleNotFoundError, check our guide on How To Solve ModuleNotFoundError.
Verify the Installation
After installation, verify MLflow is installed correctly. Run the following command:
mlflow --version
mlflow, version 1.30.0
If you see the version number, MLflow is installed successfully.
Start the MLflow Tracking Server
MLflow includes a tracking server to log experiments. Start it by running:
mlflow ui
[INFO] Starting gunicorn 20.1.0
This starts the server on http://localhost:5000. Open this URL in your browser to access the MLflow UI.
Basic MLflow Example
Here’s a simple example to test MLflow. Create a Python script named example.py:
import mlflow
# Start an MLflow run
with mlflow.start_run():
# Log a parameter (key-value pair)
mlflow.log_param("param1", 5)
# Log a metric
mlflow.log_metric("metric1", 0.85)
# Log a tag
mlflow.set_tag("tag1", "First experiment")
Run the script using:
python example.py
Check the MLflow UI at http://localhost:5000. You’ll see your logged experiment.
Install MLflow with Conda
If you use Conda, you can install MLflow in a new environment. Run:
conda create -n mlflow-env python=3.8
conda activate mlflow-env
pip install mlflow
This creates a dedicated environment for MLflow. It helps avoid conflicts with other packages.
Conclusion
Installing MLflow in Python is straightforward. Use pip or Conda to set it up. Verify the installation and start the tracking server. Now you’re ready to manage your machine learning workflows efficiently.