Cannot import name 'Mesh' from 'dolfin' (unknown location)

I’m trying to use the Mesh() function from dolfin but get the following error: “cannot import name ‘Mesh’ from ‘dolfin’ (unknown location)”

I have the latest version of fenics installed using Ubuntu (see image), so I’m not sure why this is happening.

Could you post the output of
which python3, python3 -c "from dolfin import *"
and python3 -m pip list?

jfrutschy@LAPTOP-BPVHA55G:~ which python3, python3 -c "from dolfin import *" /usr/bin/python3 jfrutschy@LAPTOP-BPVHA55G:~ python3 -m pip list
Package Version


blinker 1.4
command-not-found 0.3
cryptography 3.4.8
dbus-python 1.2.18
distro 1.7.0
distro-info 1.1build1
fenics-dijitso 2019.2.0.dev0
fenics-dolfin 2019.2.0.dev0
fenics-ffc 2019.2.0.dev0
fenics-fiat 2019.2.0.dev0
fenics-ufl 2022.2.0
httplib2 0.20.2
importlib-metadata 4.6.4
jeepney 0.7.1
keyring 23.5.0
launchpadlib 1.10.16
lazr.restfulclient 0.14.4
lazr.uri 1.0.6
more-itertools 8.10.0
mpi4py 3.1.3
mpmath 0.0.0
mshr 2019.2.0.dev0
netifaces 0.11.0
numpy 1.21.5
oauthlib 3.2.0
petsc4py 3.15.1
pip 22.0.2
pkgconfig 1.5.5
ply 3.11
pybind11 2.9.1
PyGObject 3.42.1
PyJWT 2.3.0
pyparsing 2.4.7
python-apt 2.3.0+ubuntu2.1
PyYAML 5.4.1
SecretStorage 3.3.1
setuptools 59.6.0
six 1.16.0
slepc4py 3.15.1
sympy 1.9
systemd-python 234
ubuntu-advantage-tools 27.12
ufw 0.36.1
unattended-upgrades 0.1
wadllib 1.3.6
wheel 0.37.1
zipp 1.0.0
jfrutschy@LAPTOP-BPVHA55G:~$

Could you please run each of the commands one by one, and post the output encapsulated in 3x`, i.e.

which python3

```
Put output here
```

python3 -c "from dolfin import *"

Etc…

My bad!

which python3

/usr/bin/python3

python3 -c “from dolfin import”

no output

python3 -m pip list
Package Version


blinker 1.4
command-not-found 0.3
cryptography 3.4.8
dbus-python 1.2.18
distro 1.7.0
distro-info 1.1build1
fenics-dijitso 2019.2.0.dev0
fenics-dolfin 2019.2.0.dev0
fenics-ffc 2019.2.0.dev0
fenics-fiat 2019.2.0.dev0
fenics-ufl 2022.2.0
httplib2 0.20.2
importlib-metadata 4.6.4
jeepney 0.7.1
keyring 23.5.0
launchpadlib 1.10.16
lazr.restfulclient 0.14.4
lazr.uri 1.0.6
more-itertools 8.10.0
mpi4py 3.1.3
mpmath 0.0.0
mshr 2019.2.0.dev0
netifaces 0.11.0
numpy 1.21.5
oauthlib 3.2.0
petsc4py 3.15.1
pip 22.0.2
pkgconfig 1.5.5
ply 3.11
pybind11 2.9.1
PyGObject 3.42.1
PyJWT 2.3.0
pyparsing 2.4.7
python-apt 2.3.0+ubuntu2.1
PyYAML 5.4.1
SecretStorage 3.3.1
setuptools 59.6.0
six 1.16.0
slepc4py 3.15.1
sympy 1.9
systemd-python 234
ubuntu-advantage-tools 27.12
ufw 0.36.1
unattended-upgrades 0.1
wadllib 1.3.6
wheel 0.37.1
zipp 1.0.0

Seems like dolfin is set up correctly. Could you try creating a minimal reproducible example?

Well now Spyder can’t even find dolfin:

There is an unresolved post on this exact issue:

I cannot reproduce any example without being able to import dolfin. Any idea on what to do?

This has to do with how spyder reads the $PYTHONPATH.
As you shower earlier, dolfin is installed on your system, But you haven’t configured spyder to find it properly. I do not use spyder myself, so I dont have much experience with it.

1 Like

Ok. I placed my code in the same location as my dolfin installation:


But now i get the error: “module ‘sys’ has no attribute 'getdlopenflags”
Have you seen this error before?