Conda

Cheatsheet

Set up shell environment

# e.g. conda init bash or conda init zsh
# This will append the conda initialization script into the end of your .bashrc or .zshrc file.
conda init $shell_name

Display info about conda

# Display info about conda
conda info

List all environments

conda env list

Create an environment with specified Python version

# Create a new environment
conda create -n $env_name python=$python_version

Activate environment

# Activate the environment
conda activate $env_name

Determine the current active environment

# The active environment is labelled with asterisk.
conda env list

Deactivate the current environment

conda deactivate

Remove all packages in an environment

The environment must be deactivated first.

conda remove -n $env_name --all --keep-env

Determine Python version of an environment

conda list -n $env_name -f python

Change Python version of an existing environment

conda install -n $env_name python=$python_version

Display dependencies of an environment

conda list -n $env_name

Remove an environment

conda env remove -n $env_name

Export an environment to an environment definition file

conda export -n $env_name -f $env_yaml

Create an environment from an environment definition file

conda env create -f $env_yaml

Install a package in an environment

conda install -n $env_name "$package_name=$version"

Reference