← Back to list

Setting Up Your MLflow Environment: A Complete Walkthrough from Zero to Running Code

The Business Problem

Mayurkumar Surani · 2026-06-25 01:31 · 5 claps · 16.2 min read paywalled
#mlflow #mlops #python #data-engineering #data-science
Open on Medium ↗
Wiki topics: OPS · LLMOps & Inference ML · Machine Learning 🔧 · Data Engineering 🔬 · Science · General 🏃 · Running & Endurance

Setting Up Your MLflow Environment: A Complete Walkthrough from Zero to Running Code

The Business Problem

The biggest barrier to adopting MLflow isn’t understanding the concepts — it’s getting the environment right.

Newcomers frequently face:

  • Python version conflicts between projects (one needs 3.6, another 3.9)
  • Package dependency hell where installing one package breaks another
  • IDE configuration issues that waste hours of debugging
  • Path and terminal problems on different operating systems
  • CUDA and GPU compatibility issues when using deep learning frameworks
  • Firewall and proxy issues when downloading packages in corporate environments

A poorly configured environment leads to:

  1. Frustrated teams who blame the tool instead of the setup
  2. Wasted time — setting up environments shouldn’t take longer than writing ML code
  3. Inconsistent behavior — “it works on my machine” becomes the team’s anthem
  4. Abandoned adoption — teams give up on MLOps because the initial setup was too painful

Image by author

Image by author

The Hard Truth: According to a 2023 JetBrains survey, Python developers spend an average of 11 hours per month dealing with environment and dependency issues. For data scientists, this number is even higher due to the complexity of ML library dependencies.

This guide provides a battle-tested, step-by-step setup process that works on Windows, macOS, and Linux. Follow it exactly, and you’ll go from zero to running MLflow in under 30 minutes.

How This Article Solves the Problem

We’ll walk through every step with screenshots-quality descriptions:

  1. Installing Anaconda — the Python distribution designed for data science
  2. Installing PyCharm — the IDE that makes MLflow development painless
  3. Creating a Conda environment — isolate your MLflow projects
  4. Installing MLflow and dependencies — one command to get everything
  5. Verifying the setup — run your first MLflow-tracked experiment
  6. Launching the MLflow UI — your first visual look at tracked experiments
  7. Troubleshooting common issues — OS-specific solutions for every error

Table of Contents

├── 1. Why Anaconda? Understanding Python Environment Management
│   ├── 1.1 The Case for Virtual Environments
│   ├── 1.2 Conda vs Virtualenv vs Poetry vs pipenv
│   ├── 1.3 When to Use Each Tool
│   └── 1.4 Why Conda Wins for Data Science
├── 2. Installing Anaconda
│   ├── 2.1 Windows Installation (Step by Step)
│   ├── 2.2 macOS Installation
│   ├── 2.3 Linux Installation
│   ├── 2.4 Verifying the Installation
│   └── 2.5 Post-Installation Configuration
├── 3. Installing PyCharm IDE
│   ├── 3.1 Community vs Professional Edition
│   ├── 3.2 Windows Installation with Detailed Steps
│   ├── 3.3 macOS and Linux Installation
│   └── 3.4 PyCharm First Launch Configuration
├── 4. Creating Your First MLflow Project
│   ├── 4.1 New Project with Conda Environment
│   ├── 4.2 Configuring PyCharm Terminal (Critical Windows Fix)
│   ├── 4.3 Installing Core Dependencies
│   ├── 4.4 Installing MLflow
│   └── 4.5 Complete Package List for MLflow Development
├── 5. Verifying Your Setup
│   ├── 5.1 Running the Test Script
│   ├── 5.2 Examining the mlruns Directory
│   └── 5.3 Launching the MLflow UI
├── 6. Understanding the Directory Structure
│   ├── 6.1 The mlruns Directory Layout
│   ├── 6.2 Experiment Folder Structure
│   ├── 6.3 Run Folder Structure
│   └── 6.4 meta.yaml Files Explained
├── 7. Troubleshooting Guide
│   ├── 7.1 Windows-Specific Issues
│   ├── 7.2 macOS-Specific Issues
│   ├── 7.3 Linux-Specific Issues
│   ├── 7.4 Common Package Conflict Fixes
│   └── 7.5 Network and Proxy Issues
└── 8. Next Steps and Best Practices

1. Why Anaconda? Understanding Python Environment Management

1.1 The Case for Virtual Environments

Consider this scenario: You’re working on two ML projects simultaneously.

Image by author

Image by author

Without virtual environments, you’d need two separate computers or use virtual machines. With Conda, you create isolated environments on a single machine:

# Create environment for Project A
conda create -n project_a python=3.6
conda activate project_a
pip install tensorflow==2.3 scikit-learn==0.22 numpy==1.19

# Create environment for Project B
conda create -n project_b python=3.9
conda activate project_b
pip install torch==1.12 scikit-learn==1.1 numpy==1.24

# Switch between them with one command
conda activate project_a  # Back to Project A environment
conda activate project_b  # Over to Project B environment

Code Explanation:

***conda create -n <name>*: Creates a new isolated environment with its own Python version and packages. Each environment is a self-contained directory with its own bin/, lib/, and site-packages/ folders. This is the foundation of reproducible ML environments.

***conda activate <name>*: Activates the environment, modifying your shell's PATH to point to the environment's Python and binaries. Any pip install or python command now uses the environment's isolated versions, completely separate from your system Python.

1.2 Conda vs Virtualenv vs Poetry vs pipenv

"""
COMPARISON: Python Environment Management Tools

┌──────────────────┬──────────┬────────────┬──────────┬──────────┐
│ Feature          │ Conda    │ virtualenv │ Poetry   │ pipenv   │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Python version   │ ✅ Built │ ❌ Needs   │ ❌ Needs  │ ❌ Needs  │
│ management       │ -in      │ pyenv      │ pyenv    │ pyenv    │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Non-Python deps  │ ✅ Yes   │ ❌ No      │ ❌ No    │ ❌ No    │
│ (CUDA, BLAS)     │          │            │          │          │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Data science     │ ✅ Built │ ❌ Limited │ ❌ Limited│ ❌ Limited│
│ focus            │ for this │            │          │          │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Cross-platform   │ ✅ Yes   │ ✅ Yes     │ ✅ Yes   │ ✅ Yes   │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Lock files       │ ✅ conda-│ ✅ pip     │ ✅ poetry│ ✅ Pipfile│
│                  │ lock     │ freeze     │ .lock    │ .lock    │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Package          │ 2,000+   │ 200,000+   │ 200,000+ │ 200,000+ │
│ availability     │ conda    │ pip        │ pip      │ pip      │
│                  │ packages │ packages   │ packages │ packages │
├──────────────────┼──────────┼────────────┼──────────┼──────────┤
│ Speed            │ Moderate │ Fast       │ Fast     │ Slow     │
└──────────────────┴──────────┴────────────┴──────────┴──────────┘

RECOMMENDATION: For MLflow and data science work, Conda is the superior choice
because it handles non-Python dependencies (CUDA, BLAS libraries, HDF5, etc.)
that are critical for ML frameworks.
"""

1.3 Why Conda Wins for Data Science

"""
Why Conda is the standard for MLOps:

1. CUDA and GPU Support
   Conda can install NVIDIA CUDA toolkit and cuDNN as packages:
   conda install cudatoolkit=11.3 cudnn=8.2 -c conda-forge
   virtualenv/poetry CANNOT do this — you'd need manual NVIDIA driver installation

2. Non-Python Native Libraries
   ML libraries depend on C/C++ libraries (BLAS, LAPACK, OpenMP):
   conda install blas=*=openblas  # Optimized BLAS for your CPU

3. Environment Cloning
   Create identical environments quickly:
   conda create -n new_project --clone mlflow_base

4. Environment Export
   Share exact environment specs:
   conda env export > environment.yml  # All packages with versions
   conda env create -f environment.yml  # Reproduce on any machine

5. Conda-Forge Channel
   20,000+ community-maintained ML packages:
   conda install -c conda-forge mlflow
"""

2. Installing Anaconda

2.1 Windows Installation (Step by Step)

"""
ANACONDA INSTALLATION — WINDOWS (Estimated time: 10-15 minutes)
"""

# Step 1: Download Anaconda
# Go to https://www.anaconda.com/download
# Click the Windows download button
# Choose the Python 3.9+ version (64-bit installer)
# Note: The file is ~800MB, so it may take a few minutes to download

# Step 2: Run the installer
# Double-click the downloaded .exe file
# Click "Next" through the welcome screen
# Click "I Agree" to the license agreement

# Step 3: Choose installation type
# Select "Just Me (recommended)" — this avoids needing admin privileges

# Step 4: Choose installation location
# Default: C:\\Users\\<username>\\anaconda3
# IMPORTANT: Keep the default path. Changing it can cause issues.

# Step 5: ⚠️ CRITICAL — Advanced Installation Options
# You will see TWO checkboxes:
#   [x] Add Anaconda3 to my PATH environment variable
#        THIS IS ESSENTIAL — it makes 'conda' command available from terminal
#        Without this, you'll get "conda is not recognized" errors
#
#   [x] Register Anaconda3 as my default Python 3.9
#        This makes 'python' in terminal point to Anaconda's Python
#
# BOTH MUST BE CHECKED — this is where most Windows users get stuck!

# Step 6: Click "Install"
# Installation takes 5-8 minutes

# Step 7: Open a NEW Command Prompt (not PowerShell)
# IMPORTANT: You must open a NEW terminal window after installation
# The PATH changes won't take effect in already-open terminals

2.2 macOS Installation

# Method 1: GUI Installer (Easiest)
# Download from https://www.anaconda.com/download
# Select macOS installer (64-bit)
# Open the .pkg file and follow the installer prompts

# Method 2: Command Line Installer
# Download the installer script
curl -O https://repo.anaconda.com/archive/Anaconda3-2024.10-1-MacOSX-x86_64.sh

# Verify the download (optional but recommended)
sha256sum Anaconda3-2024.10-1-MacOSX-x86_64.sh

# Run the installer
bash Anaconda3-2024.10-1-MacOSX-x86_64.sh

# Follow the prompts:
# 1. Press Enter to review license agreement
# 2. Type "yes" to accept
# 3. Press Enter to confirm installation location
# 4. Type "yes" when asked "Do you wish the installer to initialize Anaconda3?"
#    THIS IS CRITICAL — it adds conda to your shell configuration

# After installation, either open a new terminal or source your shell config:
source ~/.bash_profile  # if using bash
source ~/.zshrc         # if using zsh (macOS Catalina+ default)

# Alternatively, manually initialize conda:
conda init zsh  # or conda init bash

2.3 Linux Installation

# Download the Linux installer
wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh

# Run the installer
bash Anaconda3-2024.10-1-Linux-x86_64.sh

# Follow the prompts (same as macOS)
# CRITICAL: Say "yes" when asked to initialize conda

# Source the updated shell configuration
source ~/.bashrc

# Verify
conda --version

2.4 Verifying the Installation

# Step 1: Open a NEW terminal/command prompt
# Step 2: Check conda is installed
conda --version
# Expected output: conda 23.x.x or later

# Step 3: Check Python version
python --version
# Expected output: Python 3.9.x or later

# Step 4: List available environments
conda env list
# Expected output:
# conda environments:
# base                  *  C:\\Users\\username\\anaconda3

# The asterisk (*) shows the active environment

# Step 5: Update conda to latest version (optional but recommended)
conda update conda

# Step 6: Test conda can install packages
conda install -c conda-forge --yes --dry-run numpy
# This shows what would be installed without actually installing

2.5 Post-Installation Configuration

# Configure conda for faster performance
conda config --set auto_activate_base false
# This prevents the (base) environment from auto-activating
# on every new terminal — some users find this less intrusive

# Add conda-forge as the default channel (most ML packages are here)
conda config --add channels conda-forge
conda config --set channel_priority strict

# Verify configuration
conda config --show

3. Installing PyCharm IDE

3.1 Community vs Professional Edition

Image by author

Image by author

Recommendation: For this course, PyCharm Community Edition is sufficient. Upgrade to Professional only if you need Jupyter Notebook editing or remote development.

3.2 Windows Installation

"""
PYCHARM INSTALLATION — WINDOWS (Estimated time: 5 minutes)
"""

# Step 1: Download PyCharm Community Edition
# Visit https://www.jetbrains.com/pycharm/download/
# Click "Download" under "Community" (the free version on the right)

# Step 2: Run the installer
# Double-click the downloaded .exe file

# Step 3: Installation Options — SELECT ALL:
# [x] Create Desktop Shortcut (64-bit launcher)
# [x] Update PATH variable (restart needed)
# [x] Create Associations (.py — makes PyCharm default for Python files)
# [x] Add "Open Folder as Project" (right-click context menu)

# Step 4: Click "Install"

# Step 5: When complete, select "Reboot now" and click "Finish"
# Reboot is recommended to ensure PATH updates take effect

3.3 macOS and Linux Installation

# macOS — Download .dmg from website and drag to Applications
# OR use Homebrew:
brew install --cask pycharm-ce

# Linux — Download .tar.gz from website
# Extract and run:
tar -xzf pycharm-community-*.tar.gz
cd pycharm-community-*/bin
./pycharm.sh

# OR use snap (Ubuntu):
sudo snap install pycharm-community --classic

3.4 PyCharm First Launch Configuration

"""
When you launch PyCharm for the first time:

1. Import Settings: Choose "Do not import settings" (fresh start)
2. UI Theme: Select "Light" or "Dark" based on preference
3. Launcher Script: Check "Create a script" if offered (adds 'charm' command)

Now you're ready to create your first project!
"""

4. Creating Your First MLflow Project

4.1 New Project with Conda Environment

"""
CREATING A NEW PYCHARM PROJECT WITH CONDA:

1. Open PyCharm → Click "New Project"

2. Set Location:
   Location: C:\\Users\\<you>\\mlflow_demo
   (Choose a SHORT path — avoid deep nesting which causes Windows path length issues)

3. ⚠️ CRITICAL — Select Interpreter:
   Under "New environment using:" select "CONDA" (NOT Virtualenv)

   Options:
   - New environment using: [Conda ▼]
   - Python version: [3.9 ▼]
   - Conda executable: C:\\Users\\<you>\\anaconda3\\Scripts\\conda.exe
     (This should be auto-detected)

   IMPORTANT: Make sure it says "Conda" and not "Virtualenv" or "Pipenv"

4. Click "Create"

5. Wait for PyCharm to create the project and Conda environment
   - This may take 1-2 minutes
   - You'll see "Indexing" in the progress bar
   - Let it complete before proceeding
"""

4.2 Configuring PyCharm Terminal (CRITICAL Windows Fix)

On Windows, PyCharm defaults to using PowerShell as the terminal. PowerShel has different syntax than the Command Prompt used in most tutorials. This is the #1 source of Windows setup issues.

"""
FIX: Change PyCharm terminal from PowerShell to Command Prompt (CMD)

Step 1: File → Settings (or Ctrl+Alt+S)
Step 2: Tools → Terminal
Step 3: Under "Application Settings" → "Shell path":
         Change FROM: powershell.exe
         Change TO: cmd.exe
Step 4: Click "Apply" → "OK"
Step 5: Close and reopen the terminal (Alt+F12)
"""

# WHY THIS MATTERS:
# CMD (Command Prompt) — matches all tutorial examples:
conda activate mlflow_env
pip install mlflow
python train.py

# PowerShell — different syntax:
# conda activate mlflow_env    (may work but inconsistent)
# pip install mlflow           (works the same)
# python train.py              (works the same)
# BUT: environment variables, loops, and many commands differ

4.3 Installing Core Dependencies

# Open the PyCharm Terminal (Alt+F12)
# Make sure you see (mlflow_demo) in the prompt — this means the environment is active

# Install core ML libraries
pip install pandas numpy scikit-learn

# These are the FOUNDATIONAL libraries for MLflow:
# - pandas: Data manipulation and CSV loading
# - numpy: Numerical computations
# - scikit-learn: ML algorithms and evaluation metrics

# Install MLflow
pip install mlflow

# Install optional but recommended packages
pip install matplotlib seaborn  # For plotting in MLflow
pip install jupyter             # For Jupyter Notebook integration

# For cloud storage support (choose based on your needs):
# pip install mlflow[s3]        # AWS S3 support
# pip install mlflow[gcs]       # Google Cloud Storage
# pip install mlflow[azure]     # Azure Blob Storage

4.4 Complete Package List for MLflow Development

"""
RECOMMENDED PACKAGES FOR MLFLOW DEVELOPMENT:

Core MLflow:
  mlflow                       # The main platform
  mlflow[s3]                   # With S3 support (optional)

Data Science:
  pandas                       # Data loading and manipulation
  numpy                        # Numerical computing
  scikit-learn                 # ML algorithms and preprocessing

Visualization:
  matplotlib                   # Static plots
  seaborn                      # Statistical visualizations

Deep Learning (optional):
  tensorflow                   # TF + Keras support
  torch                        # PyTorch support
  xgboost                      # XGBoost support
  lightgbm                     # LightGBM support

Development:
  jupyter                      # Jupyter Notebooks
  black                        # Code formatting
  pylint                       # Code linting
"""

5. Verifying Your Setup

5.1 Running the Test Script

Create a new Python file in your project called verify_setup.py:

# verify_setup.py
"""
Run this script to verify your MLflow setup is working correctly.
If this runs without errors, you're ready to start!

What this script tests:
1. All core packages are installed
2. MLflow can start a run
3. MLflow can log parameters and metrics
4. The mlruns directory is created correctly
"""

import sys
import mlflow
import sklearn
import pandas as pd
import numpy as np

print("=" * 60)
print("MLflow Setup Verification")
print("=" * 60)

# Test 1: Check Python version
python_version = sys.version.split()[0]
print(f"[1/5] Python version: {python_version}")
assert python_version.startswith("3."), "Python 3.x required"
print("  ✓ PASSED")

# Test 2: Check package versions
print(f"[2/5] Package versions:")
print(f"     MLflow:      {mlflow.__version__}")
print(f"     scikit-learn: {sklearn.__version__}")
print(f"     pandas:       {pd.__version__}")
print(f"     numpy:        {np.__version__}")
print("  ✓ PASSED")

# Test 3: Check MLflow can start
print(f"[3/5] Testing MLflow import and version...")
assert hasattr(mlflow, 'start_run'), "mlflow.start_run not found"
print("  ✓ PASSED")

# Test 4: Quick MLflow tracking test
print(f"[4/5] Testing MLflow tracking...")

with mlflow.start_run() as run:
    mlflow.log_param("test_param", "hello_mlflow")
    mlflow.log_metric("test_metric", 42)
    run_id = run.info.run_id

print(f"     Run created successfully!")
print(f"     Run ID: {run_id}")
print("  ✓ PASSED")

# Test 5: Check mlruns directory
print(f"[5/5] Checking mlruns directory structure...")
import os
mlruns_path = os.path.join(os.getcwd(), "mlruns")
if os.path.exists(mlruns_path):
    print(f"     mlruns directory found at: {mlruns_path}")
    print(f"     Contents: {os.listdir(mlruns_path)}")
    print("  ✓ PASSED")
else:
    print(f"  ⚠ Note: mlruns not created yet (will be created after first run)")

print("=" * 60)
print("🎉 ALL CHECKS PASSED! MLflow setup is complete.")
print("=" * 60)

Code Explanation:

The verification script tests five things: (1) Python version is 3.x, (2) all core packages are installed with correct versions, (3) MLflow functions are importable, (4) MLflow can create a run and log data, and (5) the expected directory structure is created. If all five pass, your environment is ready.

The mlflow.start_run() block creates a test run that logs a parameter and a metric. If this succeeds without errors, MLflow is fully functional in your environment.

5.2 Examining the mlruns Directory

After running the verification script, examine the generated structure:

mlflow_demo/
├── mlruns/                          # Main tracking directory
│   ├── .trash/                      # Deleted items (recoverable)
│   ├── 0/                           # Default experiment
│   │   └── meta.yaml                # Experiment metadata
│   ├── <experiment_id>/             # Your experiment
│   │   ├── meta.yaml                # Experiment metadata
│   │   └── <run_id>/                # Individual run
│   │       ├── artifacts/           # Model files, plots
│   │       ├── metrics/             # Metric values
│   │       ├── params/              # Parameter values
│   │       ├── tags/                # Tags and metadata
│   │       └── meta.yaml            # Run metadata
├── verify_setup.py                  # Your test script
└── train.py                         # Your future training script

5.3 Launching the MLflow UI

# In the PyCharm terminal (with your Conda environment active):
mlflow ui

# Expected output:
# [2024-01-15 10:30:00] INFO: Starting Mlflow UI on http://localhost:5000

# Open your browser and navigate to:
# http://localhost:5000

What you should see:

  • An “Experiments” section on the left panel
  • A default experiment (ID: 0)
  • Your test run with the logged parameter and metric
  • The ability to explore the run’s details

6. Troubleshooting Guide

6.1 Windows-Specific Issues

Image by author

Image by author

6.2 macOS-Specific Issues

# If conda command is not found after installation:
# For bash users:
source ~/.bash_profile

# For zsh users (macOS Catalina+ default):
source ~/.zshrc

# If 'pip install' fails with "externally-managed-environment":
# This is a macOS restriction — always use conda environments:
conda activate mlflow_env  # Must be done first!
# Then install packages (pip works inside conda environments)

# If MLflow UI won't start:
mlflow ui --host 127.0.0.1  # Use explicit localhost

6.3 Linux-Specific Issues

# If 'conda' command not found:
source ~/.bashrc

# If display issues with PyCharm (headless server):
# PyCharm requires a display — use VSCode Remote or SSH instead

# If permission issues with mlruns directory:
chmod -R 755 mlruns/

6.4 Common Package Conflict Fixes

# Problem: Conflicting package versions
# Symptoms: ImportError, ModuleNotFoundError, version mismatches

# Solution 1: Create fresh environment with specific versions
conda create -n mlflow_clean python=3.9
conda activate mlflow_clean
pip install mlflow==2.10 pandas==2.1 numpy==1.24 scikit-learn==1.3

# Solution 2: Export and recreate environment
# Export current environment
conda env export > environment.yml
# Recreate on another machine
conda env create -f environment.yml

# Solution 3: Use pip's dependency resolver
pip check  # Lists all dependency conflicts
pip install --upgrade mlflow  # Upgrade to resolve conflicts

7. Next Steps and Best Practices

7.1 Working with Multiple Environments

One of the most powerful features of Conda is managing multiple project environments. Here’s a workflow for handling multiple MLflow projects:

# Create environments for different MLflow projects
conda create -n mlflow_wine python=3.9
conda create -n mlflow_churn python=3.10
conda create -n mlflow_vision python=3.9

# Each environment has its own MLflow and dependencies
conda activate mlflow_wine
pip install mlflow scikit-learn pandas

conda activate mlflow_churn
pip install mlflow xgboost lightgbm

conda activate mlflow_vision
pip install mlflow torch torchvision

7.2 Environment Export and Sharing

To share your exact environment with team members:

# Export the environment specification
conda env export > environment.yml

# Team member recreates the exact same environment
conda env create -f environment.yml

# Export only pip packages (lighter weight)
pip freeze > requirements.txt

7.3 Jupyter Notebook Integration

MLflow works seamlessly with Jupyter Notebooks:

# Install Jupyter in your environment
conda activate mlflow_env
pip install jupyter ipykernel

# Register the environment as a Jupyter kernel
python -m ipykernel install --user --name mlflow_env --display-name "MLflow Env"

# Launch Jupyter
jupyter notebook

7.4 VS Code Setup (Alternative to PyCharm)

If you prefer VS Code over PyCharm:

# Install VS Code and Python extension
# Open your project folder
# Select the Conda environment:
#   Ctrl+Shift+P -> Python: Select Interpreter -> Choose your Conda env

# VS Code extensions for MLflow development:
# - Python (Microsoft)
# - Pylance
# - Jupyter
# - GitLens

7.5 Docker Integration for Production Environments

For production deployments, Docker provides even stronger isolation than Conda:

# Dockerfile for MLflow project
FROM python:3.9-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy project files
COPY . .

# Run MLflow tracking
CMD ["mlflow", "ui", "--host", "0.0.0.0", "--port", "5000"]

7.6 Conda Environment Best Practices

  1. Name environments descriptively: mlflow_wine_project instead of env1
  2. Pin Python version explicitly: conda create -n myenv python=3.9
  3. Export environment regularly: conda env export > environment.yml
  4. Use environment.yml for team projects: Ensures everyone has the same setup
  5. Clean unused environments: conda env remove -n old_env
  6. Test in a fresh environment regularly: Catches missing dependency issues
  7. Use conda-forge channel for ML packages: conda install -c conda-forge mlflow

7.7 Complete Environment Checklist

Before starting any MLflow project, verify:

[ ] Anaconda installed and added to PATH
[ ] PyCharm installed with Conda plugin
[ ] New Conda environment created (Python 3.9+)
[ ] Core packages installed (pandas, numpy, scikit-learn)
[ ] MLflow installed
[ ] Terminal configured correctly
[ ] Verification script runs without errors
[ ] mlruns directory is created after first run
[ ] MLflow UI launches successfully
[ ] Package dependencies exported to requirements.txt

7.8 Setting Up MLflow in CI/CD Pipelines

For automated ML pipelines, you can set up MLflow in your CI/CD system:

# .github/workflows/mlflow_setup.yml
name: Setup MLflow Environment

on:
  push:
    branches: [main]

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Setup Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.9'

    - name: Create and activate environment
      run: |
        python -m venv venv
        source venv/bin/activate
        pip install --upgrade pip

    - name: Install dependencies
      run: |
        source venv/bin/activate
        pip install mlflow pandas numpy scikit-learn

    - name: Verify MLflow
      run: |
        source venv/bin/activate
        python -c "import mlflow; print(f'MLflow {mlflow.__version__} ready')"

7.9 MLflow in Docker Containers

For production deployments, package your MLflow environment in Docker:

# Dockerfile.mlflow
FROM python:3.9-slim

RUN pip install mlflow pandas numpy scikit-learn torch

EXPOSE 5000

CMD ["mlflow", "ui", "--host", "0.0.0.0", "--port", "5000"]
# Build and run
docker build -t mlflow-server -f Dockerfile.mlflow .
docker run -p 5000:5000 -v $(pwd)/mlruns:/app/mlruns mlflow-server

7.10 Environment Troubleshooting Flowchart

MLflow not working? Follow this decision tree:

1. Can you import mlflow?
   YES -> Go to step 2
   NO -> Run `pip install mlflow` in active environment

2. Can you start a run?
   YES -> Go to step 3
   NO -> Check mlruns directory permissions

3. Can you log a metric?
   YES -> Go to step 4
   NO -> Check tracking URI configuration

4. Can you launch the UI?
   YES -> Setup complete! Start building models.
   NO -> Is port 5000 in use? Try `mlflow ui --port 8080`

8. Conclusion

A properly configured environment is the foundation of a productive MLflow workflow. The time invested in setting up Anaconda + PyCharm + Conda environments pays back exponentially by eliminating “it works on my machine” problems.

Key Takeaways:

  1. Anaconda is the recommended distribution for MLflow work — it handles Python versions, non-Python dependencies, and environment isolation
  2. Always use Conda environments for MLflow projects — never install MLflow globally
  3. PyCharm Community Edition is free and sufficient — the Conda integration is seamless
  4. Windows users MUST configure the terminal — switch from PowerShell to CMD to avoid syntax issues
  5. The mlruns directory is your tracking database — understand its structure to master MLflow
  6. Verification script saves hours — run it after every setup to catch issues early
  7. Docker and CI/CD integration extends MLflow to production environments

Pro Tip: Create a base MLflow environment with the most common packages that you can clone for new projects:

conda create -n mlflow_base python=3.9
pip install mlflow pandas numpy scikit-learn jupyter
conda create -n new_project --clone mlflow_base

메타데이터
post_id
25f0ca7b54c0
slug
setting-up-your-mlflow-environment-a-complete-walkthrough-from-zero-to-running-code-25f0ca7b54c0
url
https://medium.com/@mayursurani/setting-up-your-mlflow-environment-a-complete-walkthrough-from-zero-to-running-code-25f0ca7b54c0
canonical_url
https://medium.com/@mayursurani/setting-up-your-mlflow-environment-a-complete-walkthrough-from-zero-to-running-code-25f0ca7b54c0
author_url
https://medium.com/@mayursurani
status
ok
fetched_at
2026-07-11 22:47:18