Installing FEniCS Python package inside Slicer

I tried troubleshooting. I realised that the DOLFIN Python component needs to be built separately to link with the DOLFIN C++ libraries.

I got it working now using a “hybrid” approach:

  1. Install FEniCS 2019.1.0 using Ubuntu PPA
    (see: https://fenics.readthedocs.io/en/latest/installation.html#ubuntu-ppa)

  2. Install fenics Python-only components in Slicer using pip:

     {MY_SLICER_DIR}/bin/PythonSlicer -m pip install fenics
    
  3. Download and install Python header files in Slicer:

     wget -P ${MY_SLICER_DIR}/lib/Python/include/python3.6m/ https://github.com/python/cpython/archive/v3.6.7.tar.gz
     cd ${MY_SLICER_DIR}/lib/Python/include/python3.6m/
     tar --strip-components=2 -zxf v3.6.7.tar.gz cpython-3.6.7/Include
    
  4. Install Python interface of DOLFIN:

     ${MY_SLICER_DIR}/bin/PythonSlicer -m pip install ${MY_FENICS_SRC}/dolfin/python
    

Step 3 was suggested by @jcfr when I was developing Slicer FEniCS in Boston. Maybe it would be worthwhile to include these headers within the Slicer distribution. It is the only complicated step in the installation process here.