Can not import name

Hii , I am very new to fenics. I installed it on ubuntu 22.04. Initially everything was working well but today I updated everything on my system. After updating when I am running the same programme , I am getting this error-

Traceback (most recent call last):
File “/home/sushil/Documents/Python tutorial/test3.py”, line 1, in
from fenics import *
File “/usr/lib/python3/dist-packages/fenics/init.py”, line 7, in
from dolfin import *
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/init.py”, line 138, in
from . import parameter
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/parameter/init.py”, line 11, in
from ffc import default_jit_parameters
File “/usr/lib/python3/dist-packages/ffc/init.py”, line 24, in
from ffc.compiler import compile_form, compile_element
File “/usr/lib/python3/dist-packages/ffc/compiler.py”, line 129, in
from ffc.codegeneration import generate_code
File “/usr/lib/python3/dist-packages/ffc/codegeneration.py”, line 37, in
import ffc.uflacs.language.cnodes as L
File “/usr/lib/python3/dist-packages/ffc/uflacs/init.py”, line 23, in
from ffc.uflacs.uflacsrepresentation import compute_integral_ir
File “/usr/lib/python3/dist-packages/ffc/uflacs/uflacsrepresentation.py”, line 26, in
from ffc.representationutils import initialize_integral_ir
File “/usr/lib/python3/dist-packages/ffc/representationutils.py”, line 28, in
from ufl.cell import cellname2facetname
ImportError: cannot import name ‘cellname2facetname’ from ‘ufl.cell’ (/usr/lib/python3/dist-packages/ufl/cell.py)
I will be very thankful to you for any suggestion.

As you are trying to use legacy fenics, you need to use a specific branch of ufl: Configure Mixed Dimensional Branch with ParMETIS - #7 by dokken

Please note that we advice all new users to use DOLFINx and not DOLFIN, Ref: The new DOLFINx solver is now recommended over DOLFIN

You would have installed from the FEniCS PPA. dolfinx has just been upgraded to 0.4. The ffc error was collatoral damage.

It should be repaired now, please update again and upgrade to the latest package.

In regards to dokken’s suggestion to use DOLFINx rather than DOLFIN, it can be installed with

sudo apt-get install fenicsx

or

sudo apt-get install python3-dolfinx
1 Like

Hi, I tried installing FEniCS for the first time today (just a few hours ago) from the PPA and I got the same error as suchilkv, is it possible for it not to be fixed yet?
I’m running ubuntu 20.04, here is the error message:

Traceback (most recent call last):
  File "p_laplacian.py", line 3, in <module>
    from fenics import *
  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 138, in <module>
    from . import parameter
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfin/parameter/__init__.py", line 11, in <module>
    from ffc import default_jit_parameters
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/__init__.py", line 24, in <module>
    from ffc.compiler import compile_form, compile_element
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/compiler.py", line 129, in <module>
    from ffc.codegeneration import generate_code
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/codegeneration.py", line 37, in <module>
    import ffc.uflacs.language.cnodes as L
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/uflacs/__init__.py", line 23, in <module>
    from ffc.uflacs.uflacsrepresentation import compute_integral_ir
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/uflacs/uflacsrepresentation.py", line 26, in <module>
    from ffc.representationutils import initialize_integral_ir
  File "/home/ana/.local/lib/python3.8/site-packages/ffc/representationutils.py", line 28, in <module>
    from ufl.cell import cellname2facetname
ImportError: cannot import name 'cellname2facetname' from 'ufl.cell' (/usr/lib/python3/dist-packages/ufl/cell.py)

Your error message is different: you’ve got a local installation of ffc, instead of the ubuntu package.

Thanks!! Ill make another post to see if someone can help me

As @dparsons is saying:

you should remove the local install of ffc

1 Like

Oh!! Any ideas on how to do that? because I’ve tried doing sudo apt remove fenics but then it all stops working because it says I dont have fenics at all

Do you know how it got installed locally in the first place? It wasn’t apt, apt does not install to /home/*/.local/.

In the first instance you should try using the uninstall feature of the tool used to install it there.

I dont know, because I only used apt. Weird, I’ll keep looking on how it got installed there, thanks for the help

pip would install there (e.g. pip3 install --user ffc), so you could try pip3 uninstall --user ffc.

If nothing else works, you could try simply deleting /home/ana/.local/lib/python3.8/site-packages/ffc. Might be worth inspecting that local site to see if anything else has infiltrated into your system.

1 Like

That solved it, thanks!!!