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
conda info --envs
# or
conda env list
conda env remove -n project_name
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
Search for available packages
conda search package_name
Project Workflow Examples
# 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
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
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
Clean unused packages to free space
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.