No module named 'dolfin.cpp'

Hello, I’m trying to use FeniCS but I’m getting the error

No module named 'dolfin.cpp'

This error first appeared after reinstalling FeniCS, and appears also when installing it on google colab. Here’s the entire error log:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ad1b407335d7> in <module>()
     39 # Begin demo
     40 
---> 41 from dolfin import *
     42 
     43 # Source term

/usr/lib/petsc/lib/python3/dist-packages/dolfin/__init__.py in <module>()
     32 
     33 # Import cpp modules
---> 34 from .cpp import __version__
     35 
     36 from .cpp.common import (Variable, has_debug, has_hdf5, has_scotch,

ModuleNotFoundError: No module named 'dolfin.cpp'

Anyone know any solution ? Thanks.

My guess is that you’re using an Ubuntu installation, and there’s a mismatch with the versions that your dolfin is built against.

If dolfin is found and it’s just cpp that’s missing, then the problem will be your python version. You can see which python it’s been compiled against from the version tags in the cpp files in /usr/lib/petsc/lib/python3/dist-packages/dolfin/. The Ubuntu python packages are built against the python versions that are provided by the given Ubuntu release.

Google colab is not properly maintained by the way. Google has not been able to update it past ubuntu 18.04, which only supports python3.6. Most packages today need python3.8 or later. A work-around is available at https://fem-on-colab.github.io/

Thank you for your prompt reply. I’m indeed using Ubuntu, 18.04 to be precise. I will get back to you once I’ve explored and tinkered with the versions and installations I have.