Reproducible Scientific Computing & Data Analysis

Reproducible computational environments with Conda

Henry Lütcke - henry.lutcke@id.ethz.ch

Scientific IT Services, ETH Zurich

5 November 2025

1 Introduction to Conda

1.1 Reference

1.2 Installing conda

For evaluation purposes
The default Anaconda installation is only recommended for evaluation or testing purposes!
In production
Due to Anaconda Terms of Service, the use of alternative, community-supported channels is recommended in production

. . .

channel_priority: strict
channels:
- conda-forge

1.3 Starting conda

Command Line Interface

$ conda deactivate
Conda on Windows
Conda on macOS

1.4 Version, Info and Help

conda Environment

A directory that contains specific installed packages (system libraries, python/R modules, …).

base Environment

The default environment that you have when installing conda.

$ conda --version

$ conda --help

$ conda info

. . .

1.4.1 Exercise

  1. Which version of conda are you running?

  2. Inspect the output of conda info especially: platform, Python version, active environment, base environment and channel URLs.

1.5 Create / Clone and List all Envs

$ conda create --name py38 python=3.8

$ conda create --name py38-clone --clone py38

$ conda env list

1.6 Activate and Deactivate Env

Check Python version on:

  1. the system,
  2. the base env, and
  3. the new py38 env.
      $ python --version

      $ conda activate 
(base)$ python --version

(base)$ conda activate py38
(py38)$ python --version

1.7 List Installed Packages

(py38)$ conda list
(py38)$ conda list --name base

(py38)$ conda list python
(py38)$ conda list ^lib

1.8 Search and Install Packages

Conda channels

(py38)$ conda search numpy=1.21
(py38)$ conda install numpy=1.21.6

(py38)$ conda install pandas="<1.5"

1.9 Update Packages and Revisions

(py38)$ conda update pandas
(py38)$ conda update --all

(py38)$ conda list --revisions
(py38)$ conda install --revision 2
(py38)$ conda list --revisions

1.10 Environment File - YAML Format

Environment File

A YAML file that contains all information to create an environment.

YAML file: seaborn.yml

name: seaborn
# important: do not use 'defaults', but always include 'nodefaults'
  - conda-forge
  - nodefaults

dependencies:
  - seaborn=0.12.2

Note: seaborn is is a Python data visualization library based on matplotlib.

1.11 Environment File to Environment and back

 (py38)$ conda env create --file seaborn.yml
 (py38)$ conda activate seaborn

(seaborn)$ conda env export
(seaborn)$ conda env export --no-builds
(seaborn)$ conda env export --from-history
(seaborn)$ conda env export --no-builds > seaborn_export.yaml
(seaborn)$ conda env create --file seaborn_export.yaml --name seaborn_export

Note: The build specification is generally platform dependent.

Note: The packages might not be available on all platforms.

. . .

1.11.1 Identical Environments

Spec File

A text file that contains all information to create an identical environment.

(seaborn)$ conda list --explicit 

(seaborn)$ conda list --explicit > seaborn_spec_file.txt
(seaborn)$ conda create --name seaborn_explicit --file seaborn_spec_file.txt

Warning: Use the spec file on a similar platform.

1.12 Removing environments

Finally, try yourself to remove some or all of the environments that we just created.

Hint: Have a look at the documentation for the conda env command: conda env --help

1.13 Removing environments - Solution

(seaborn)$ conda activate base
(base)$ conda env remove --name seaborn

Note: You cannot remove the active environment!

1.14 What Did We Learn?