Conda takes 20+ minutes to solve environment when package is already installed

A Common Problem: Suboptimal Channel Prioritization

Anaconda distribution is designed and tested to use the anaconda channel (a subset of defaults) as its primary channel. Adding conda-forge in either a higher- (channel_priority: strict) or equal-priority (channel_priority: flexible) configuration opens up many of the packages to be sourced from Conda Forge instead, and this is where Conda struggles to solve.

Including conda-forge both expands the search as well as opens other packages to be subject to channel switching, and since the anaconda package includes dozens of packages, this can be a huge satisfiability problem to solve. This is often most problematic after the first time conda-forge is added into a user’s configuration.

Solutions

There are two high-level ways to improve performance: simplify the solving problem or use a faster solver. Of course, these are not mutually exclusive – feel free to be both thoughtful about what you demand of your solver and adopt optimized tools.

Option 1: Optimize Channel Prioritization

When the anaconda metapackage is installed in an environment, keep the defaults channel at highest priority (first channel in .condarc) and set channel_priority: strict. See the documentation on Managing Channels.

Additionally, one can forcefully prioritize the defaults channel with commands like

conda update -n base --override-channels -c defaults conda

Option 2: Mamba

Mamba is a drop-in replacement for the conda CLI that is faster (compiled) and in my experience tends to be more aggressive in pruning. Once installed, it runs similar to conda, e.g.,

mamba update -n base conda

Note on Alternative Configuration

Many users find the coupling of their environment management infrastructure (Conda) to a large working environment (Anaconda) to be less than ideal. A popular alternative configuration is to maintain a minimal base environment, and if Anaconda is ever needed, to create a new environment with the anaconda package installed.

Alternative options for base environments include

  • Miniconda – minimal base with defaults channel priority
  • Miniforge – minimal base with conda-forge channel priority
  • Mambaforge – Miniforge base + Mamba

Leave a Comment