<aside> 🐍

conda is used for package, dependency and environment management. Instead of installing software to the entire machine, you install it only in a contained environment.

</aside>

conda is cross-platform and enables reproducibility of old code, even when some packages and dependencies have been updated in the meantime. It can be used for any language and can even act as a manager for bioinformatic software. We also use it to manage our Python environments, which makes it easy to invoke different Python versions as needed for different tasks.

Installation

There are two flavors of conda — Anaconda and Miniconda. We use the more lightweight Miniconda:

curl -O <https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh>
bash ~/Miniconda3-latest-MacOSX-arm64.sh
# default installs to $HOME/miniconda3
source ~/.zshrc

<aside> 💽

Use the arm64 build on Apple Silicon. On an older Intel Mac, substitute x86_64 in the filename.

</aside>

This downloads the Miniconda installer, runs it, and installs to your $HOME folder by following the prompts. It also adds $HOME/miniconda3/bin to your lookup $PATH, which lets you run conda executables without referring explicitly to their location.

Usage and an example

Create a new environment that uses a specific Python version:

conda create --name test_environment python=3.9

You can see a list of all the environments you have ever created with conda env list (* marks the current environment):

# conda environments:
#
base                  *  /Users/$username/miniconda3
dev                      /Users/$username/miniconda3/envs/dev
test_environment         /Users/$username/miniconda3/envs/test_environment

To activate the environment you just created:

source activate test_environment

Now you are in the virtual environment, using that Python version as a default. You can check with python --version, and see the path to your environment's Python with which python.

The main way to adjust an environment is by installing Python packages you'll use in your analysis. The primary means of installation is conda install {package name}. If you receive a PackagesNotFoundError, search to identify other means of conda installation. This may include tapping different channels such as bioconda or conda-forge:

conda install --channel bioconda {package name}

If a package is not available from conda, you may use pip install {package name}. While conda attempts to be compatible with pip, you may occasionally run into issues with packages installed through this route.

Cleaning