conda and Anaconda¶
conda is a cross-platform package and environment manager. It can install Python packages as well as non-Python dependencies (C libraries, compilers, etc.).
Anaconda vs Miniconda¶
| Distribution | Size | Includes |
|---|---|---|
| Anaconda | ~3 GB | Python + 250+ packages (NumPy, Pandas, Jupyter, etc.) |
| Miniconda | ~50 MB | Python + conda only |
Recommendation: Start with Miniconda and install only what you need.
Installation¶
Miniconda¶
Download from: https://docs.conda.io/en/latest/miniconda.html
# Linux
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
# macOS
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
bash Miniconda3-latest-MacOSX-x86_64.sh
Verify Installation¶
conda --version
conda info
Environment Management¶
Create Environment¶
conda create -n myenv python=3.11
conda create -n dataenv python=3.11 numpy pandas matplotlib
Activate / Deactivate¶
conda activate myenv
# ... do work ...
conda deactivate
List Environments¶
conda env list
conda info --envs
Remove Environment¶
conda env remove -n myenv
Clone Environment¶
conda create -n newenv --clone oldenv
Package Management¶
Install Packages¶
conda install numpy
conda install numpy pandas scikit-learn
conda install numpy=1.24.0 # Specific version
Update Packages¶
conda update numpy
conda update --all # Update all packages
Remove Packages¶
conda remove numpy
Search Packages¶
conda search numpy
conda search "numpy>=1.20"
List Installed Packages¶
conda list
conda list numpy # Filter by name
Channels¶
Channels are repositories where conda looks for packages.
Default Channel¶
Anaconda's default channel (defaults) is managed by Anaconda Inc.
Add Channel¶
conda config --add channels conda-forge
conda config --set channel_priority strict
Install from Specific Channel¶
conda install -c conda-forge numpy
conda install -c pytorch pytorch
View Channels¶
conda config --show channels
Environment Files¶
Export Environment¶
conda env export > environment.yml
conda env export --no-builds > environment.yml # More portable
Example environment.yml:
name: myenv
channels:
- conda-forge
- defaults
dependencies:
- python=3.11
- numpy=1.24
- pandas=2.0
- pip
- pip:
- some-pip-only-package
Create from File¶
conda env create -f environment.yml
Update from File¶
conda env update -f environment.yml
conda vs pip¶
| Feature | conda | pip |
|---|---|---|
| Package source | Anaconda repo / conda-forge | PyPI |
| Non-Python deps | ✅ Yes | ❌ No |
| Environment mgmt | ✅ Built-in | ❌ Needs venv |
| Dependency solver | SAT solver | Basic resolver |
| Binary packages | Pre-compiled | Wheels or source |
| Speed | Slower | Faster |
Using pip with conda¶
You can use pip inside a conda environment:
conda activate myenv
conda install pip
pip install some-package-not-on-conda
Best practice: Install conda packages first, then pip packages.
# environment.yml
dependencies:
- numpy
- pandas
- pip
- pip:
- package-only-on-pypi
Anaconda Licensing¶
⚠️ Important: Since 2020, Anaconda's terms of service require a paid license for commercial use (organizations with 200+ employees).
Free alternatives: - conda-forge (community channel) - Miniforge (conda-forge default installer) - Mambaforge (Miniforge + mamba)
See the conda-forge and Miniforge page for details.
Common Commands¶
| Command | Description |
|---|---|
conda create -n env python=3.11 |
Create environment |
conda activate env |
Activate environment |
conda deactivate |
Deactivate environment |
conda install pkg |
Install package |
conda update pkg |
Update package |
conda remove pkg |
Remove package |
conda list |
List packages |
conda env list |
List environments |
conda env export > env.yml |
Export environment |
conda env create -f env.yml |
Create from file |
conda clean --all |
Remove unused packages/caches |
Configuration¶
View Config¶
conda config --show
Common Settings¶
# Always activate base environment
conda config --set auto_activate_base true
# Don't activate base by default
conda config --set auto_activate_base false
# Set channel priority
conda config --set channel_priority strict
# Add conda-forge
conda config --add channels conda-forge
.condarc File¶
# ~/.condarc
channels:
- conda-forge
- defaults
auto_activate_base: false
channel_priority: strict
Key Takeaways¶
- Miniconda is lighter than Anaconda
- conda manages both Python packages and system dependencies
- Use environments to isolate projects
- Channels are package repositories (defaults, conda-forge)
- Can use pip inside conda environments (conda packages first)
- Check licensing for commercial use — consider conda-forge/Miniforge