Skip to content

Instantly share code, notes, and snippets.

@ahgraber
Last active September 16, 2021 20:01
Show Gist options
  • Save ahgraber/7b52390f4a9842ad1334844ed139ee80 to your computer and use it in GitHub Desktop.
Save ahgraber/7b52390f4a9842ad1334844ed139ee80 to your computer and use it in GitHub Desktop.
conda cheatsheet

Conda cheatsheet and reminders

Installation

Install miniconda

mamba is a faster, drop-in replacement for conda. You can swap almost all commands between conda & mamba...

The only difference is that you should still use conda for activation and deactivation.

Code below will still use conda for compatibility, but use of mamba is strongly encouraged, especially for resolving/installing environments with complicated dependencies.

Install mamba to the base environment. Check if conda is in PATH and set as default python

conda install mamba -n base -c conda-forge

Note: After installing mamba, leave base environment untouched and work only in other envs

Creating environments

Create a new conda environment with

conda create --name <env_name> python=3.7 <package_1> <other-channel::package_2> ...

Clone an existing environment with

conda create --name <myclone> --clone <exisiting_env>

Create a conda environment using environment.yml file with

conda env create -f /path/to/environment.yml

Activate an environment

Activate an environment to use it (or to install packages to it):

conda activate <env_name

Add environment to jupyter

Install conda environment to jupyter:

python -m ipykernel install --user --name=<env_name>

Export environments for sharing/saving

Export exact specifications:

conda env export --name ENVNAME > environment.yml

Export an environment for cross-platform:

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

Delete an environment

conda remove --name <env_name> --all

Undo / Roll back changes to an environment

IMPORTANT: setting to revision #0 basically uninstalls all environments! Use --revision 1 at minimum

conda list --revisions  # lists all changes in order
conda install --revision <rev_num>  # resets state to <rev_num>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment