Conda & Anaconda Quick Reference
Manage dependencies and environments like a pro – for data science, ML, and general
Python development.
What are Anaconda and Conda?
- Anaconda – a full‑featured distribution of Python/R with 250+ pre‑installed data science packages.
- Miniconda – a minimal installer that includes conda and Python, allowing you to install only what you need.
- Conda – the package manager that works across Linux, macOS, Windows; manages environments and dependencies.
Installation
Download Anaconda
- Official download page
- Graphical installer or command‑line (for Linux).
Install Miniconda (Command Line)
# Linux / macOS curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh # Follow prompts, then restart shell # macOS (Apple Silicon) curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh bash Miniconda3-latest-MacOSX-arm64.sh # Windows – download .exe and run
Basic Conda Commands
# Check version conda --version # Update conda conda update conda # Update all packages in base conda update --all # Show configuration conda info conda info --envs
Environment Management
Environments isolate dependencies for different projects.
Create, Clone, Remove
# Create environment with specific Python conda create --name myenv python=3.10 # Create environment with packages conda create --name myenv python=3.10 numpy pandas # Clone environment conda create --name newenv --clone myenv # Remove environment conda remove --name myenv --all # List all environments conda env list # Activate / deactivate conda activate myenv conda deactivate
Export / Import Environment
# Export to YAML (reproducible) conda env export --name myenv > environment.yml # Export only explicit package versions (faster) conda list --explicit > packages.txt # Create environment from YAML conda env create -f environment.yml # Update environment from YAML conda env update -f environment.yml --prune
Package Management
Search, Install, Update, Remove
# Search for package conda search numpy # Install package in active environment conda install numpy conda install numpy=1.24.0 conda install numpy pandas matplotlib # Install from specific channel conda install -c conda-forge scikit-learn # Install with pip (inside conda environment) pip install some-package # Update a package conda update numpy # Remove a package conda remove numpy # List installed packages in active environment conda list # List packages in a specific environment conda list -n myenv
Channels
Channels are repositories for conda packages.
- defaults – Anaconda's official channel (stable).
- conda‑forge – community‑driven, more up‑to‑date packages.
- bioconda – bioinformatics packages.
- pytorch – official PyTorch channel.
# Add a channel (priority order) conda config --add channels conda-forge conda config --set channel_priority strict # Show configured channels conda config --show channels # Install from a specific channel conda install -c conda-forge package-name # Set default channel conda config --set default_channel conda-forge
Managing Python Versions
# Create environment with specific Python conda create -n py38 python=3.8 conda create -n py39 python=3.9 conda create -n py310 python=3.10 # Change Python version in an existing environment conda install python=3.9 # (in active environment) # Check Python version python --version
Advanced Commands
Cleanup and Cache
# Remove unused packages and cache conda clean --all # Remove only package tarballs conda clean -t # Remove index cache conda clean -i
Environment File with Pip Packages
environment.yml:
name: myenv
channels:
- conda-forge
- defaults
dependencies:
- python=3.10
- numpy
- pandas
- pip
- pip:
- requests
- flask
Clone root environment (base)
conda create --name baseclone --clone base
Run a command in a specific environment without activating
conda run -n myenv python script.py
Common Use Cases
Data Science Setup
conda create -n ds python=3.10 conda activate ds conda install numpy pandas matplotlib seaborn jupyter notebook conda install -c conda-forge scikit-learn scipy
Deep Learning with GPU
conda create -n tf python=3.10 conda activate tf conda install tensorflow-gpu # for CUDA # Or for PyTorch (with CUDA) conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
Best Practices
- Create a new environment for each project – avoid dependency conflicts.
- Export environment.yml – share with team / version control.
- Use conda‑forge for up‑to‑date packages (set as priority channel).
- Pin exact versions in environment.yml for reproducibility.
- Prefer conda install over pip when possible (conda handles dependencies better).
- Keep base environment minimal – avoid installing too many packages in base.
- Use
conda cleanperiodically to free disk space. - Use
mambaas a faster drop‑in replacement for conda (install via conda). - Name environments descriptively (e.g., project‑name, py310‑ml).
- Document dependencies – include both conda and pip packages in environment.yml.
Mamba (Faster Alternative)
# Install mamba conda install mamba -c conda-forge # Use mamba instead of conda for faster installs mamba install numpy pandas mamba create -n newenv python=3.10
Troubleshooting
- Slow installation? – use mamba or configure faster channels.
- Environment conflicts? – solve by using
conda install(new solver).--solver libmamba - Out of disk space? – run
conda clean -a. - Package not found? – check channel; use
conda search. - Mixing pip and conda? – install pip packages after conda packages to avoid conflicts.
- Permission issues? – install Miniconda/Anaconda for the user (no admin required).
📌 Quick Reference
Environments: conda create, activate, deactivate, env list, remove
Packages: conda install, update, remove, list, search
Export/Import: conda env export > environment.yml; conda env create -f environment.yml
Channels: defaults, conda-forge, bioconda; add with conda config
Clean: conda clean --all
Mamba: faster, drop‑in replacement (install via conda)
Best practice: one environment per project, export YAML, use conda‑forge
Packages: conda install, update, remove, list, search
Export/Import: conda env export > environment.yml; conda env create -f environment.yml
Channels: defaults, conda-forge, bioconda; add with conda config
Clean: conda clean --all
Mamba: faster, drop‑in replacement (install via conda)
Best practice: one environment per project, export YAML, use conda‑forge