Advanced Conda Usage Advanced

Take your Conda skills to the next level with advanced configuration, package building, reproducibility tools, and integration with Docker and CI/CD pipelines.

conda config and .condarc

The .condarc file (located at ~/.condarc) controls all Conda behavior. You can edit it directly or use conda config commands:

Terminal
# View all configuration
$ conda config --show

# Set a configuration value
$ conda config --set auto_activate_base false
$ conda config --set channel_priority strict

# Set default threads for faster downloads
$ conda config --set default_threads 4

# Set environment directories
$ conda config --set envs_dirs /path/to/custom/envs
YAML
# Example ~/.condarc file
channels:
  - conda-forge
channel_priority: strict
auto_activate_base: false
show_channel_urls: true
default_threads: 4
solver: libmamba

Offline Installs

Install packages without internet access by downloading them first:

Terminal
# Download packages without installing
$ conda install numpy --download-only

# Install from local package cache
$ conda install --use-local numpy

# Create a local channel from downloaded packages
$ conda install --offline numpy

Building Conda Packages

Use conda-build to create your own packages:

Terminal
# Install conda-build
$ conda install conda-build

# Build a package from a recipe
$ conda build my-recipe/

# Install the built package
$ conda install --use-local my-package

meta.yaml Recipe File

Every conda package needs a meta.yaml recipe file:

YAML
package:
  name: my-tool
  version: "1.0.0"

source:
  url: https://github.com/user/my-tool/archive/v1.0.0.tar.gz
  sha256: abc123...

build:
  number: 0
  script: python -m pip install . -vv

requirements:
  host:
    - python >=3.9
    - pip
  run:
    - python >=3.9
    - numpy >=1.24
    - pandas >=2.0

test:
  imports:
    - my_tool

about:
  home: https://github.com/user/my-tool
  license: MIT
  summary: A helpful tool

conda-lock for Reproducibility

conda-lock creates fully resolved, cross-platform lock files for exact reproducibility:

Terminal
# Install conda-lock
$ pip install conda-lock

# Generate lock file from environment.yml
$ conda-lock -f environment.yml -p linux-64 -p osx-arm64

# Install from lock file (exact versions)
$ conda-lock install conda-lock.yml

Mamba: Faster Conda

Mamba is a drop-in replacement for Conda with a much faster dependency solver written in C++:

Terminal
# Install Mamba
$ conda install -c conda-forge mamba

# Use Mamba exactly like Conda
$ mamba create -n fast-env python=3.11 numpy pandas
$ mamba install -c conda-forge scikit-learn

# Or use Conda's built-in libmamba solver
$ conda config --set solver libmamba
Modern Conda includes libmamba: Since Conda 23.10+, the fast libmamba solver is the default. You may not need to install Mamba separately anymore.

Docker + Conda

Dockerfile
FROM continuumio/miniconda3:latest

# Copy environment file
COPY environment.yml /tmp/environment.yml

# Create the environment
RUN conda env create -f /tmp/environment.yml && \
    conda clean -afy

# Activate environment in every shell
SHELL ["conda", "run", "-n", "myenv", "/bin/bash", "-c"]

COPY . /app
WORKDIR /app

CMD ["conda", "run", "-n", "myenv", "python", "app.py"]

CI/CD with Conda

YAML
# GitHub Actions example
name: CI
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: conda-incubator/setup-miniconda@v3
        with:
          environment-file: environment.yml
          activate-environment: myenv
          python-version: "3.11"
      - run: pytest tests/

Performance Tips

TipHow
Use libmamba solverconda config --set solver libmamba
Increase download threadsconda config --set default_threads 4
Use strict channel priorityconda config --set channel_priority strict
Clean package cacheconda clean --all
Install packages togetherSingle conda install with all packages

Almost Done!

Complete the course with best practices, troubleshooting tips, and a handy FAQ.

Next: Best Practices →