0

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.

  • If you are fine with installing fenics inside a conda environment instead of virtualenv I can give you detailed instructions how to do it, including parallel reading and writing of h5/xdmf files to save your solutions. – pbit24 Dec 12 '22 at 22:28
  • @pbit24 I suppose I'd need to install anaconda in that case then? I guess I'll try it out if there's no other solutions. Thank you. – user289522 Dec 12 '22 at 22:31

2 Answers2

0

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?

Daniel V
  • 1
  • 5
  • Ah forgot about cmake, I just pip installed it there but stil same issue. What's the difference in installing pybind11 vs using pip install? If you click on the pybind11 hyperlink, it just tells you to use pip install pybind11 in the docs. – user289522 Dec 12 '22 at 22:34
  • IDK about the difference, unless the command referenced above puts it in a different dir? anyhow cmake is a **MUST** – Daniel V Dec 12 '22 at 22:37
  • Also, going off **pbit24's** idea, I remembered, since you are using a virtual enviroment, (going off what you said here: "inside my virtualenv") You have to install it ***INSIDE*** the virtual enviroment for it to work, not on your system. I don't know what you are using for that, but it probably doesn't accept cmd commands... (speaking from the standpoint of someone who has never used virtual enviroments before) – Daniel V Dec 12 '22 at 23:57
  • @user289522 I checked the github, and it has the os requirements [here.](https://github.com/FEniCS/dolfinx#binary) Check to see if that helps. Also you can contact fenics directly [here.](https://github.com/FEniCS/dolfinx#contact) – Daniel V Dec 13 '22 at 00:27
  • @user289522 check the reqs – Daniel V Dec 14 '22 at 04:35
0

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.

pbit24
  • 418
  • 4
  • 12
  • Ah, tried following your steps but still gave the same error when I tried importing dolfin – user289522 Dec 12 '22 at 23:23
  • Are you importing dolfin in the correct python kernel? Are you using some kind of IDE? If yes you need to connect it to the python kernel of your fenics environment. When you open a new terminal and activate the fenics environment, first type "python" (without quotes) and hit enter. This will start your python kernel in the terminal. Then import dolfin typing "from dolfin import *" (also without quotes) and hit enter. Does it work now? – pbit24 Dec 12 '22 at 23:41
  • I'm using Pycharm. So I've changed my interpreter to the fenics environment, then opened up a command prompt, typed python and then imported dolfin and same error again. The fenics environment is activated in the terminal that I open up within pycharm as it says (fenics) before the project path. – user289522 Dec 13 '22 at 00:11
  • Could you give us some more information on your operating system? What linux are you using? Or are you using WSL? – pbit24 Dec 13 '22 at 15:17
  • im on windows 10, not linux. @pbit24 – user289522 Dec 14 '22 at 00:57
  • 1
    So you installed your python, virtualenv, conda directly on Windows 10?, without a virtual machine or docker or WSL = Windows Subsystem for Linux? If so, this should be the reason. As far as I know dolfin does only work on Linux, it is not compatible with Windows. So you will need to either install some kind of Linux on your computer, or use a virtual machine or WSL or a docker image. – pbit24 Dec 14 '22 at 16:24
  • 1
    Yep purely on windows 10. Thanks I will look into those tools then @pbit24 – user289522 Dec 15 '22 at 04:27