Installation Instructions

Get started with NumCosmo

Author

NumCosmo developers

Download

Version 0.29.0 of NumCosmo is the latest release version available at NumCosmo’s GitHub page github releases.

For macOS, use Homebrew and the dependency list in the GitHub Actions workflow.

Build Status License: GPL v3 codecov

Install using conda

Install NumCosmo and its dependencies with conda. Install Anaconda or Miniconda first if needed.

Installing NumCosmo using conda-forge

conda-forge provides precompiled NumCosmo packages. Use the conda-forge channel or a conda-forge-only environment from Miniforge.

Using Conda

We recommend installing NumCosmo from the conda-forge channel, which provides pre-compiled binaries for Linux and macOS. You can install it with:

conda install -c conda-forge numcosmo

Or if you have conda-forge in your channels:

conda install numcosmo

Current release info

Name Downloads Version Platforms
Conda Recipe Conda Downloads Conda Version Conda Platforms

Development Environment

Conda Development Environment

Create the development environment from the repository root:

conda env create -n numcosmo_developer -f environment.yml
conda activate numcosmo_developer
meson setup build --libdir=$CONDA_PREFIX/lib --prefix=$CONDA_PREFIX
meson compile -C build

To test the installation, run the unit tests:

meson test -v -C build

If you prefer using the library without installation, export specific environment variables. A script is generated in the build directory for easy execution (and optional addition to shell initialization):

source build/numcosmo_export.sh

This script sets essential environment variables such as LD_LIBRARY_PATH and PYTHONPATH, enabling library usage without installation. Keep in mind that these variables apply only to the current shell session, so you’ll need to source this script each time you open a new terminal. Note that these variables may interfere with meson setup, so unset them before rerunning the setup command.

Installation

In general, developers do not need to install the library. However, if you wish to install it in your conda environment, use the following command:

meson install -C build

Note that during library development, you’ll need to run meson install each time you modify the library to reflect changes in the conda environment.

Other Development Environments

For developers, NumCosmo can be installed from the source code. This provides the latest version of the code on the master branch. It is recommended for those interested in contributing to the project.

Requirements

The requirements below can be found on most Linux distributions. Click here for a list of package names for Debian-like distributions.

  • C compiler (gcc, clang, icc, etc)
  • Fortran compiler (gfortran, ifort, etc)
  • Glib >= 2.44.0 – Data structures, threads, portability, memory allocation, etc.
  • GSL >= 2.8 – Several computational tools.
  • GMP >= 4.3.2 – Big integers library.
  • MPFR >= 2.4.2 – Multiple precision float library.
  • GObject-introspection – Middleware layer between C libraries (using GObject) and language bindings. It is needed to use NumCosmo from other languages.
  • PyGObject – Needed to use NumCosmo from Python. Note that pygobject3 refers to the PyGObject version (not Python’s version).
  • CFITSIO – A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format.
  • FFTW3 >= 3.1.2 – Discrete Fourier transform library.
  • NLOpt – Several general purpose minimization algorithms.

Note: libfyaml (used for YAML/JSON (de)serialization) does not need to be installed separately – NumCosmo bundles the parser/emitter core it needs under numcosmo/external/libfyaml.

Optional packages
Installing Prerequisites

To streamline the installation process, we provide instructions for installing prerequisites on Debian-like systems (including Ubuntu) and Mac OS using Homebrew.

Debian-like Systems (including Ubuntu)

On Debian-like systems, you can install the required packages from the main repositories using the following command:

sudo apt-get install gcc gfortran pkg-config libglib2.0-dev \
  gobject-introspection gir1.2-glib-2.0 gir1.2-glib-2.0-dev \
  libgirepository-2.0-dev libcairo2-dev libgsl-dev libgmp3-dev libmpfr-dev \
  libflint-dev libfftw3-dev libopenblas-dev libnlopt-dev libcfitsio-dev \
  libhdf5-dev libopenmpi-dev

This is the same set the CI builds against; see .github/actions/apt-deps. Two packages are needed only for particular tasks and are left out above: gtk-doc-tools to build the API documentation, and uncrustify to run the indentation check before contributing.

Note: GSL must be 2.8 or newer. Ubuntu 24.04 LTS ships 2.7.1, so it cannot build NumCosmo from distro packages – use 25.10 or later, or the conda installation described at the top of this page.

Note: in recent Debian and Ubuntu releases, the package name changed from libflint-arb-dev to libflint-dev.

Mac OS using Homebrew

For Mac OS users, Homebrew simplifies the installation process. Execute the following command to install the required packages:

brew install gfortran glib gobject-introspection pygobject3 \
  gsl gmp mpfr fftw openblas nlopt cfitsio gtk-doc

Installing pygobject3 from Homebrew avoids pip having to build PyGObject from source against Homebrew’s interpreter.

Python packages using pip

For the build system and the Python package with the dependencies of its tests and command-line interface, run from the repository root:

pip install meson ninja -e ".[test]"

For type checking with mypy, add the type stubs:

pip install mypy pygobject-stubs types-tabulate

Building from repository

To build from the git repository, follow the steps below. These instructions are for developers; if you just want to use NumCosmo, you should install it using conda.

NumCosmo uses the meson build system and requires Python >= 3.11. Meson is available on most distributions, but if you don’t have it, you can follow the instructions.

  • Configure the project, here we use the default options:
git clone https://github.com/NumCosmo/NumCosmo.git
cd NumCosmo
meson setup build
  • Compile everything
meson compile -C build
  • Optionally run the library unit testing
meson test -v -C build
  • Install the library (optional). Note that most developers don’t want to install the library since they prefer to update/modify the library without installing it.
meson install -C build
  • To use the library without installing it, you need to export some environment variables. A script is generated in the build directory that you can source (and optionally add to your shell initialization):
source build/numcosmo_export.sh

Compiling example_simple.c

cd $NUMCOSMO_DIR/examples

gcc -D_GNU_SOURCE -Wall example_simple.c -o example_simple -lnumcosmo -lgsl -lm $(pkg-config glib-2.0 gobject-2.0 --libs --cflags)