Skip to content

Instantly share code, notes, and snippets.

@abidanBrito
Last active November 11, 2024 11:37
Show Gist options
  • Save abidanBrito/ce9266fdd6cea6e401ceae7ac0effd9b to your computer and use it in GitHub Desktop.
Save abidanBrito/ce9266fdd6cea6e401ceae7ac0effd9b to your computer and use it in GitHub Desktop.

Conda Cheatsheet

Set up

Installing miniconda

Linux / WSL

curl -LO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Windows

winget install -e --id Anaconda.Miniconda3

PowerShell profile

# Miniconda
$env:Path += ";$env:USERPROFILE\AppData\Local\miniconda3\condabin"

Updating miniconda

conda update conda
conda --version (check version)

Disable auto-activation (when firing up a prompt)

conda config --set auto_activate_base false

Channels

Listing active channels

conda config --show channels
conda config --show default_channels

Adding channels

conda config --append channels <channel_name>

Environments

Activating & deactivating environments

conda activate (base environment)
conda activate <env_name>
conda deactivate

Listing environments

conda env list
conda info --env

Creating environments

From scratch

conda create -n <env_name> (empty env)
conda create -n <env_name> <pkg_name> (env with one package, can add more)
conda create -n <env_name> python=<version> (env with a specific python version)

From a yaml file

conda env create -f <path_to_yaml_file>

Removing environments

conda env remove -name <env_name>
conda remove -n <env_name> --all (removes all packages and their dependencies)

Updating an environment

conda env update -f .\environment.yml

Cloning environments

conda create -n <new_env_name> --clone <env_name>

Sharing an environment

conda env export > environment.yml

Cleaning an environment (unused packages, caches and temporary files)

conda clean --yes --all
conda clean --yes --packages

Variables

conda env config vars list
conda env config vars set my_var=value
conda env config vars unset my_var -n test-env

Packages

Using pip as a package manager

conda install -n <env_name> pip
conda activate <env_name>
pip <pip_subcommand>

Listing packages

conda list (current env)
conda list -n <env_name> (from within a different env)
conda list -n <env_name> <pkg_name> (check for a pkg within an env)

Installing packages

conda install <pkg_name>
conda install -c <channel_name> <pkg_name>

Updating packages

conda update <pkg_name>
conda update -c <channel_name> <pkg_name>
conda update --all

Removing packages

conda remove <pkg_name>

Other useful (unsorted) commands

conda env update --prune (update to match yaml env file)
conda init powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

NOTE: you can specify the environment you want to affect using the -n and -p flags. The -n flag allows you to name the environment and -p allows you to specify the path to the environment.

Useful arguments

--yes, -y (don't ask for permission)
--display, -d (dry run; useful to try out potentially dangerous actions)
--all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment