How can I install the FeniCS dolfin module?

1.7k Views Asked by At

So I'm trying to install FEniCS from the instructions here. I did the

pip3 install fenics-ffc --upgrade

inside my virtualenv and it worked but when I try to import dolfin I get a ModuleNotFound error. I'm not sure how to get dolfin installed. I did

pip install pybind11

to get pybind11 installed then copied the code for dolfin installation into my cmd

FENICS_VERSION=$(python3 -c"import ffc; print(ffc.__version__)")
git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/dolfin
git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/mshr
mkdir dolfin/build && cd dolfin/build && cmake .. && make install && cd ../..
mkdir mshr/build   && cd mshr/build   && cmake .. && make install && cd ../..
cd dolfin/python && pip3 install . && cd ../..
cd mshr/python   && pip3 install . && cd ../..

but it just spat out dozens of errors like:

FENICS_VERSION=$(python3 -c"import ffc; print(ffc.version)") 'FENICS_VERSION' is not recognized as an internal or external command, operable program or batch file.

git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/dolfin Cloning into 'dolfin'...

fatal: Remote branch $FENICS_VERSION not found in upstream origin

git clone --branch=$FENICS_VERSION https://bitbucket.org/fenics-project/mshr Cloning into 'mshr'...

fatal: Remote branch $FENICS_VERSION not found in upstream origin

There were lots more errors after too. Am I not supposed to paste the dolfin code into cmd? I don't know much about this stuff so unsure of how to get the dolfin module. I've previously only used pip to get my packages but this does not work for dolfin as it doesn't appear to be on PyPI.

2

There are 2 best solutions below

5
On

Do you have cmake? It says in the docs you need it. Also its says to to this to install pybind11 not pip install pybind11

For building optional Python interface of DOLFIN and mshr, pybind11 is needed since version 2018.1.0. To install it:

wget -nc --quiet https://github.com/pybind/pybind11/archive/v${PYBIND11_VERSION}.tar.gz
tar -xf v${PYBIND11_VERSION}.tar.gz && cd pybind11-${PYBIND11_VERSION}
mkdir build && cd build && cmake -DPYBIND11_TEST=off .. && make install

Also what is your os?

7
On

So here is how you can install fenics 2019.1 using conda (miniconda):

Install Conda:

First go to https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html

and follow the installation instructions.

Create a conda environment for fenics:

  1. Open a terminal and type:

conda create -n fenics

  1. To activate the created environment "fenics", type:

conda activate fenics

If you want the fenics environment to be activated automatically everytime you open a new terminal, then open you .bashrc file (should be under /home/username/.bashrc) and add the line "source activate fenics" below the ">>> conda initialize >>>" block.

Install fenics:

Type all these commands:

  1. conda install -c conda-forge h5py=*=*mpich*
  2. conda install -c conda-forge fenics
  3. pip install meshio
  4. pip install matplotlib
  5. pip install --upgrade gmsh
  6. conda install -c conda-forge paraview
  7. pip install scipy

The second command will take a while. I added a few nice to have programs like gmsh and paraview which will help you to create meshes and view your solutions.