I have updated my system today (Ubuntu 18.04) and fenics is no longer working.
MWE:
from fenics import *
This produces:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/fenics/__init__.py", line 7, in <module>
from dolfin import *
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/__init__.py", line 144, in <module>
from .fem.assembling import (assemble, assemble_system, assemble_multimesh, assemble_mixed,
File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py", line 38, in <module>
from ufl.form import sub_forms_by_domain
ImportError: cannot import name 'sub_forms_by_domain'
In case anybody wants to reproduce the issue, here is a Dockerfile:
# Using ubuntu 20.04 as basis
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y -qq software-properties-common git
RUN add-apt-repository ppa:fenics-packages/fenics
RUN apt-get install -y --no-install-recommends fenics
RUN python3 -c "from fenics import *"
RUN apt-get install -y python3-pip
RUN pip3 install --user ufl
RUN python3 -c "from fenics import *"
As LiborKudela indicated, the first place to look is whether you’ve got any user-installed python modules, installed manually by pip for instance. If you have that then your versions will not be consistent and you will get this kind of error. Python gives priority to user installed modules.
When I was trying to remove the package using pip3 uninstall ufl I could not fix it either, since pip did not see it for some reason. I think that uninstalling the package using pip, leaves some stuff in the site-packages directory.
I had to remove the ufl package manually using:
cd /home/username/.local/lib/python3.6/site-packages/
sudo rm -r ufl/
I’m late to the discussion, but you can also just see where python is picking up your package and remove it if necessary. Your PYTHONPATH be be prioritising directories containing old versions.
If possible, I would like to report this issue (me and my collaborators are frequently running into it on different systems, also without any previous history). I just don’t know where. Can anybody help me here? Sorry, if this is slightly off-topic, but from my point of view the solution above offers help to FEniCS users, but does not really solve the underlying problem.
I have the same problem… and a already tried all this tips that you talking about and don’t work for me until now… /=
I try to run the simp_topology_optimization.ipynb:
%matplotlib notebook
import dolfin
import ufl
from dolfin import *
import matplotlib.pyplot as plt
import numpy as np
And i have this error:
ImportError Traceback (most recent call last)
in
1 get_ipython().run_line_magic(‘matplotlib’, ‘notebook’)
----> 2 import dolfin
3 import ufl
4 from dolfin import *
5 import matplotlib.pyplot as plt
/usr/lib/petsc/lib/python3/dist-packages/dolfin/init.py in
142 from .common.plotting import plot
143
→ 144 from .fem.assembling import (assemble, assemble_system, assemble_multimesh, assemble_mixed,
145 SystemAssembler, assemble_local)
146 from .fem.form import Form
/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/assembling.py in
36 from dolfin.function.multimeshfunction import MultiMeshFunction
37
—> 38 from ufl.form import sub_forms_by_domain
39
40 all = [“assemble”, “assemble_mixed”, “assemble_local”, “assemble_system”,
ImportError: cannot import name ‘sub_forms_by_domain’ from ‘ufl.form’ (/home/cassiano/.local/lib/python3.8/site-packages/ufl/form.py)
But when I go check it in the form.py, the function sub_forms_by_domain don exists… =/
I searched on forum and a find some issues from the subdomain topic. Is this related?
I hope that someone could help me with this issue, please.
You have removed ufl from the python3.6 local installation, but from the error you see that it is actually getting imported from the python3.8 directory. Remove that one too.