๐Ÿš€ Migrating from Conda to UV

If youโ€™ve been managing Python environments with Anaconda/Miniconda, you can now move to UV, a fast, Rust-based Python package & environment manager. This guide shows how to:

  1. Back up your Conda environments
  2. Uninstall Conda
  3. Install UV
  4. Recreate environments in UV from your Conda backups

1. ๐Ÿ“ฆ Back Up Conda Environments

Run the following PowerShell script to export all Conda environments to YAML files:

# backup-conda-envs.ps1

# Directory to save environment backups
$BackupDir = "$HOME\conda_env_backups"
mkdir $BackupDir -Force | Out-Null

# List all Conda environments
$envs = conda env list | Select-String -Pattern "^\S" | ForEach-Object {
    ($_ -split "\s+")[0]
}

# Export each environment to YAML
foreach ($env in $envs) {
    $outfile = Join-Path $BackupDir "$env.yaml"
    Write-Host "Backing up $env -> $outfile"
    conda env export -n $env | Out-File -Encoding utf8 $outfile
}

Write-Host "โœ… Backup complete. Environments saved in $BackupDir"

After running, youโ€™ll find all your environments backed up in:

C:\Users\<YourName>\conda_env_backups\

2. ๐Ÿ—‘๏ธ Uninstall Conda

  • If you installed Anaconda:
Start-Process "C:\ProgramData\Anaconda3\Uninstall-Anaconda3.exe"
  • If you installed Miniconda:
Start-Process "C:\Users\$env:USERNAME\Miniconda3\Uninstall-Miniconda3.exe"

(Optional cleanup):

Remove-Item -Recurse -Force "$HOME\Anaconda3" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$HOME\Miniconda3" -ErrorAction SilentlyContinue

Also, remove Conda-related entries from your PATH in System Environment Variables.


3. โšก Install UV

Install UV using the official PowerShell script:

irm https://astral.sh/uv/install.ps1 | iex

Verify installation:

uv --version

4. ๐Ÿ”„ Restore Environments in UV

UV does not consume Conda YAML files directly, but you can restore by extracting the Python version and pip dependencies.

Hereโ€™s a PowerShell script that converts each Conda backup into a new UV environment:

# restore-conda-envs-to-uv.ps1

$BackupDir = "$HOME\conda_env_backups"
$files = Get-ChildItem $BackupDir -Filter *.yaml

foreach ($file in $files) {
    $envName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
    Write-Host "Restoring $envName from $file"

    # Read YAML lines
    $yaml = Get-Content $file.FullName

    # Extract Python version (fallback to latest if not found)
    $pythonLine = $yaml | Where-Object { $_ -match "python=" }
    if ($pythonLine) {
        $pythonVersion = ($pythonLine -split "=")[1]
    } else {
        $pythonVersion = "3.11"
    }

    # Create UV environment
    uv venv $envName --python $pythonVersion

    # Extract pip dependencies section
    $inPip = $false
    $deps = @()
    foreach ($line in $yaml) {
        if ($line -match "^- pip:") { $inPip = $true; continue }
        if ($inPip) {
            if ($line -match "^- ") {
                $dep = $line.Trim().TrimStart("-").Trim()
                $deps += $dep
            } else {
                $inPip = $false
            }
        }
    }

    if ($deps.Count -gt 0) {
        Write-Host "Installing pip dependencies for $envName..."
        uv pip install --python $pythonVersion $deps
    } else {
        Write-Host "No pip dependencies found for $envName"
    }

    Write-Host "โœ… Environment $envName restored"
}

This script:

  • Reads each Conda YAML file
  • Extracts the Python version
  • Creates a matching UV environment
  • Installs pip-based dependencies

โš ๏ธ Note: Packages that were Conda-only (non-pip) wonโ€™t transfer automatically. You may need to manually install them with equivalent pip/UV packages.


5. โœ… New Workflow with UV

  • Create environment:
uv venv myenv --python 3.11
  • Activate environment:
uv venv activate myenv
  • Install packages:
uv pip install numpy pandas matplotlib
  • Run scripts:
uv run myscript.py

๐Ÿ“Š Conda โ†’ UV Command Cheatsheet

Task Conda UV
Create environment conda create -n myenv python=3.10 uv venv myenv --python 3.10
Activate environment conda activate myenv uv venv activate myenv
Deactivate environment conda deactivate deactivate (standard venv behavior)
List environments conda env list uv venv list
Install package conda install numpy uv pip install numpy
Install from file conda install --file requirements.txt uv pip install -r requirements.txt
Export environment conda env export > env.yaml uv pip freeze > requirements.txt
Remove environment conda env remove -n myenv uv venv remove myenv
Run script in env conda run -n myenv python script.py uv run script.py
Update package conda update numpy uv pip install --upgrade numpy

๐ŸŽฏ Summary

  • Backed up Conda environments โ†’ YAML
  • Uninstalled Conda completely
  • Installed UV as your new manager
  • Restored Python environments in UV
  • Mapped Conda commands โ†’ UV equivalents

Now youโ€™re fully Conda-free, and UV handles your Python environments in a faster, simpler, and more reproducible way.