# Python CAMB¶

CAMB (Code for Anisotropies in the Microwave Background), a cosmology code for calculating CMB, lensing, galaxy count, dark-age 21cm power spectra, matter power spectra and transfer functions. There are also general utility function for cosmological calculations such as the background expansion, distances, etc. The main code is Python with numerical calculations implemented efficiently in Python-wrapped modern Fortran.

See the CAMB python example notebook for an introductory set of examples of how to use the CAMB package. This is usually the fastest way to learn how to use it and quickly see some of the capabilities.

For a standard non-editable installation use:

pip install camb [--user]


The –user is optional and only required if you don’t have write permission to your main python installation. If you want to work on the code from GitHub, you can also just install in place without copying anything using:

pip install -e /path/to/CAMB [--user]


You will need ifort or gfortran 6 or higher installed (and on your path) to compile; see Fortran compilers for compiler installation details if needed. A compiled library for Windows is also provided, and is used if no gfortran installation is found on Windows machines. If you have gfortrand installed, “python setup.py make” will build the Fortran library on all systems (including Windows without directly using a Makefile), and can be used to update a source installation after changes or pulling an updated version.

Anaconda users can also install from conda-forge using:

conda install -c conda-forge camb


with no need for a Fortran compiler (unless you want to use custom sources/symbolic compilation features). Check that conda installs the latest version, if not try installing in a new clean conda environment.

After installation the camb python module can be loaded from your scripts using “import camb”. You can also run CAMB from the command line reading parameters from a .ini file, e.g.:

camb inifiles/planck_2018.ini


You may need to check your python scripts directory is in your path for this to work. Alternatively from the source package root directory (after make but without installation) use:

python camb.py inifiles/planck_2018.ini


Main high-level modules:

Other modules: