Skip to content

Instantly share code, notes, and snippets.

@yatender-oktalk
Created April 20, 2025 10:07
Show Gist options
  • Save yatender-oktalk/401c47e8ec78e46476c386dc6f7abfcc to your computer and use it in GitHub Desktop.
Save yatender-oktalk/401c47e8ec78e46476c386dc6f7abfcc to your computer and use it in GitHub Desktop.

Conda Cheatsheet for Data Science/ML Projects

Basic Environment Management

Create a new environment with specific Python version

conda create -n project_name python=3.10

Activate/deactivate environments

# Activate
conda activate project_name

# Deactivate (return to base)
conda deactivate

List all environments

conda info --envs
# or
conda env list

Remove an environment

conda env remove -n project_name

Package Management

Install packages with conda

conda install numpy pandas matplotlib scikit-learn
conda install -c conda-forge xgboost lightgbm

# Install specific version
conda install numpy=1.23.5

Install packages with pip in conda environment

# First activate the environment
conda activate project_name
pip install transformers wandb tensorflow-addons

List installed packages

conda list

Search for available packages

conda search package_name

Project Workflow Examples

ML Project Setup

# Create environment
conda create -n ml_project python=3.10

# Activate
conda activate ml_project

# Install core data science packages
conda install numpy pandas matplotlib scikit-learn scipy jupyterlab

# Install deep learning framework (PyTorch)
conda install -c pytorch pytorch torchvision

# Save environment definition
conda env export > environment.yml

Create environment from environment.yml

conda env create -f environment.yml

Create project-specific kernel for Jupyter

conda activate project_name
python -m ipykernel install --user --name project_name --display-name "Python (Project Name)"

Managing Multiple Python Versions

Create environments with different Python versions

conda create -n py38 python=3.8
conda create -n py39 python=3.9
conda create -n py310 python=3.10
conda create -n py311 python=3.11

Check Python version in current environment

python --version

Environment Sharing & Reproducibility

Export environment to YAML

conda env export > environment.yml

Export only manually installed packages (more portable)

conda env export --from-history > environment.yml

Create environment from YAML file

conda env create -f environment.yml

Export pip requirements

pip freeze > requirements.txt

Config and Performance Tips

Set conda to not auto-activate base

conda config --set auto_activate_base false

Speed up conda by using mamba (drop-in replacement)

# Install mamba
conda install -c conda-forge mamba

# Use mamba like conda but faster
mamba install numpy pandas

Configure conda channels priority

conda config --add channels conda-forge

Working with GPU packages

Install PyTorch with CUDA support

conda install -c pytorch pytorch torchvision torchaudio pytorch-cuda=11.8

Install TensorFlow with GPU support

conda install -c conda-forge tensorflow-gpu

Common Troubleshooting

Clean unused packages to free space

conda clean -a

Update conda itself

conda update -n base conda

Reset environment when packages conflict

conda deactivate
conda env remove -n problem_env
conda create -n problem_env python=3.10

To create a GitHub Gist:
1. Go to https://gist.github.com/
2. Paste this content into the main text area
3. Name the file "conda_cheatsheet.md"
4. Click "Create public gist" or "Create secret gist"

This gist covers all the essential conda commands and workflows to refer back to when you need a quick reminder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment