This site requires JavaScript to be enabled

Using conda with Miniforge to manage environments

656 views

4.0 - Updated on 2025-02-06 by Thomas Bozonelos

3.0 - Updated on 2024-07-10 by Thomas Bozonelos

2.0 - Updated on 2024-07-10 by Thomas Bozonelos

1.0 - Authored on 2022-02-28 by Marcia Teckenbrock

Using conda with Miniforge to manage environments

 

Intended for:

Conda users

 


Scenario/Use case:

Use conda with Miniforge to manage software environments

 


Instructions:

conda is a command-line executable that can be used to manage software environments. It also manages the installation of software into such environments. It primarily is used to support the installation of Python-based software, but it is not limited to that. It can be used in conjunction with pip but care needs to be taken when doing so.

 

Usage of Anaconda or Miniconda

Anaconda, the not-completely-free product, is *not* allowed at Fermilab. Usage of the conda software with the actually-free conda-forge distribution is allowed. Access to anaconda.com and Miniconda are blocked on the Fermilab network. 

https://inside.fnal.gov/2024/10/anaconda-and-miniconda-access/?utm_source=newsletter&utm_medium=email&utm_campaign=ft-241010

 

Install using Miniforge

Miniforge provides an installation of conda for Windows, Linux, and macOS. For all platforms, the user-level installation seems best for many users. That is what is described here.

On MacOS, Homebrew installation of Miniforge is not recommended because when Homebrew updates Miniforge, all environments are lost. Instead, it is recommended to use the shell installer for miniforge-conda; this does an installation under $HOME which automatic updates do not mangle. The installed version of conda can be updated with the usual conda update conda command.

 

Creating a new installation to match an existing one

The most convenient way to create a new conda environment to match an existing one is to use the conda env export function as shown below. However, three important cautions must be kept in mind.

  1. Remove any mention of the defaults channel in the output YAML file.
  2. Edit the path to the environment to that which you want to use.
  3. Make sure the name of the environment matches the prefix path you provide if the path is into one of the ones that conda manages.

The command to generate the YAML file (which you must edit, as noted above) is:

# Use either "-n environment-name" or "-p path-to-environment" to identify the environment you want to copy

conda env export --from-history [-n <environment-name> | -p <path-to-environment>] > environment.yaml

The --from-history is critical. That is the flag that limits the report to include only those packages that were directly requested during the creation (or updating) of the environment. When moving to a different OS, or from Anaconda to Miniforge, the detailed list of dependencies calculated by conda can vary. By including only what was directly requested, this allows conda to find the set of supporting packages that are needed and consistent.

Before creating the new environment, edit the environment.yaml file as noted above. To create the new environment, based on that YAML file, the command is:

conda env create -f environment.yaml

 

Cautions

Pay attention to .condarc files

A centralized installation of any version of conda includes a site-level configuration file .condarc somewhere in the system-managed directories. The command conda info will tell you where this is (look for "populated config files"; it is typically the first one listed). You probably also have a user-level configuration file (typically at $HOME/.condarc. Finally, each environment might also contain a .condarc file specific to that channel.

To avoid entanglements with licensed software from Anaconda, Inc., you need to make sure none of your .condarc files includes the channel defaults. This channel contains packages curated by Anaconda, Inc., and the use of this channel is controlled by their licensing terms.