Miniforge: conda, mamba and conda-forge

Miniforge: conda, mamba and conda-forge#

In this chapter, we give indications about how to install Miniforge and use conda/mamba. Please, if you encounter problems, fill an issue here to explain what you did and what are the errors (please copy / paste the error log).

The first step is to install Miniforge, which is a modified version of Miniconda using by default the community driven conda-forge channel.

On Windows, download the Windows installer and follow the instructions given in conda-forge/miniforge. Do not forget to manually add the C:\Users\myusername\miniforge3\condabin folder to the path environment variable.

Download the installer using curl or wget or your favorite program. For eg:

wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"

or

curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"

Execute the installer and initialize conda:

bash Miniforge3-$(uname)-$(uname -m).sh -b
$HOME/miniforge3/bin/conda init --all

When it’s done, open a new terminal (click on ctrl-alt-t) and check that the line in the new terminal starts with (base). The indication (base) means that you use the base “environment”.

However, working in the base environment is not a good practice and it is better to disable the auto activation with:

conda config --set auto_activate_base false

conda and mamba are 2 commandline tools to manage software installations and create “environments”.

Definition: environment

A environment is a set of programs and libraries with particular versions. An environment is defined by the software installed on your computer and by environment variables, in particular the variable $PATH, which contains all the paths where your shell looks for programs (you can read the output of echo $PATH).

It is very useful to be able to create different environments for different tasks. It is usually better to keep the base environment only for the conda software and to use different environments for other tasks. We will use this strategy here. We will have

  • 1 environment for some basic libraries used in this course (called main),

  • 1 environment with Mercurial (automatically created with the tool conda-app)

  • 1 environment with Fluidsim and MPI (called env-fluidsim-mpi)

conda takes the programs that it installs from “channels”. We are going to use the largest open-source community driven channel called conda-forge. With Miniforge, conda-forge is by default the main channel.

We can start by creating the main environment with the commands:

conda env create --file https://foss.heptapod.net/fluiddyn/fluidhowto/-/raw/branch/default/book/python/conda-env-main.yml
Content of the .yml file describing the environment?
name: main
dependencies:
  # standard packages
  - ipython
  - numpy
  - matplotlib
  - ipympl
  - scipy
  - pandas
  # jupyterlab and few nice extensions
  - jupyterlab
  - jupyterlab-myst
  - jupyterlab-spellchecker
  - jupyterlab-variableInspector
  # to be able to use this environment with Spyder
  - nb_conda_kernels

While conda creates the environment, we can study the most important conda commands:

  • conda activate main

  • conda deactivate

  • conda search fluidsim

  • conda create -n name-env numpy pandas

  • conda env list

Tip

One can add the line conda activate main at the end of the file ~/.bashrc.

Install and setup Mercurial#

To install Mercurial, you can do:

conda activate base
pip install conda-app -U
conda-app install mercurial

Close the terminal (ctrl-d) and reopen a new terminal (ctrl-alt-t)! The commands hg and hg-setup should be available. However, you still have to finalize Mercurial setup, which can be done by running:

hg-setup init

Warning

Mercurial has to be correctly setup! Since we will Github and Gitlab, the Mercurial extension hg-git has to be activated so the line hggit = in the configuration file ~/.hgrc is mandatory. However, hg-setup should have set this for you.

You can check that everything is right by running hg version -v.