Python package requires fortran compilers

I’m trying to get binder to run some code that require a python package called camb (Python CAMB — Code for Anisotropies in the Microwave Background (CAMB) 1.3.4 documentation). The package is essentially a wrapper for some old fortran code and when installing it will often give the error ‘Exception: you need ifort or gfortran 6 or higher to compile (found: none)’ when trying to install. This is fine when running the code locally as I can just install the necessary compilers on my own machine. However, I have no idea how to tell/get binder to also install the necessary compilers as they aren’t a python package. Any advice would be appreciated.

You’ll want to use apt.txt to get the compiler. See about the apt.txt configuration file here.

I have binderized examples that get gfortran that way:

Or alternately, make use of the already-in-the-container mamba with an environment.yml, e.g.

channels:
- conda-forge
dependencies:
- camb

Per build, this may represent a time savings, comparing:

  • run the apt solver
  • download the apt packages
  • install all the app packages
  • solve with pip
  • download the pip packages
  • compile the fortran code

vs:

  • solve with mamba
  • download the conda packages
  • install the conda packages

That seems to have worked. Thank you!

Good point. I should have also included a pointer to your excellent coverage of the advantages of switching to the use of mamba via environment.yml here for such cases.
For those who aren’t aware of mamba but maybe have seen conda (Anaconda/Miniconda) around, mamba is a fast conda package builder because it reimplents the conda package manager in C++, see here for more details about it.
The environment.yml option is in the Binder documentation here.

1 Like