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:
# 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
# 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:
# 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:
# 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:
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:
# 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++:
# 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
Docker + Conda
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
# 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
| Tip | How |
|---|---|
| Use libmamba solver | conda config --set solver libmamba |
| Increase download threads | conda config --set default_threads 4 |
| Use strict channel priority | conda config --set channel_priority strict |
| Clean package cache | conda clean --all |
| Install packages together | Single conda install with all packages |
Almost Done!
Complete the course with best practices, troubleshooting tips, and a handy FAQ.
Next: Best Practices →Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX