No module named 'fenics' on Ubuntu Anaconda

I’ve installed fenicsx using the following commands

conda create -n fenicsx-env
conda activate fenicsx-env
conda install -c conda-forge fenics-dolfinx mpich pyvista

However, when I go into python (I’ve also tried python3, but that is not part of the anaconda installation) and type

import fenics

I get the error: No module named ‘fenics’.
When typing

conda list

It shows the following fenics modules:
fenics
fenics-basix
fenics-basix-pybind11-abi
fenics-dijitso
fenics-dolfinx
fenics-ffc
fenics-ffcx
fenics-fiat
fenics-libbasix
fenics-libdolfinx
fenics-ufcx
fenics-ufl

On the other hand, I am able to import fenics if I install the legacy fenics using the following commands in the fenicsproject environment:

conda create -n fenicsproject -c conda-forge fenics
source activate fenicsproject

In this environment, typing

conda list

shows the following fenics modules:
fenics
fenics-dijitso
fenics-dolfin
fenics-ffc
fenics-fiat
fenics-libdolfin
fenics-ufl

dolfinx is the latest version of the FEniCS project. dolfin is part of the legacy FEniCS project. It seems that your environments are working correctly. With your fenicsx-env environment you should import dolfinx and with the legacy FEniCS environment you should import dolfin.

When you call import fenics using legacy FEniCS this is all that’s happening: Bitbucket

This highlights one of the motivating factors for developing the latest version dolfinx. There should be just one way to do anything.

1 Like