Dolfinx module not found

I have installed the fenicsx on my Ubuntu 22.04 as follows:

sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt update
sudo apt install fenicsx

But when I try to import “dolfinx”, I get module not found error.

(carp) $ /usr/bin/python3
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dolfinx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dolfinx'
>>> 

During the installation, it looks like it did install python3-dolfinx but I cant locate it! There were no errors during installation.

...
Setting up python3-slepc4py (3.15.1-2build1) ...
Setting up python3-slepc4py-real (3.15.1-2build1) ...
Setting up libdolfinx-real-dev:amd64 (1:0.8.0-6~ppa3~jammy1) ...
Setting up libdolfinx-dev:amd64 (1:0.8.0-6~ppa3~jammy1) ...
Setting up python3-dolfinx-real (1:0.8.0-6~ppa3~jammy1) ...
Setting up python3-dolfinx:amd64 (1:0.8.0-6~ppa3~jammy1) ...
Setting up fenicsx (2:0.8.0.2~ppa1~jammy1) ...
...

However, the pip list does not show dolfinx having been installed.

(carp) $ /usr/bin/pip3 list|grep fenics
fenics-basix           0.8.0
fenics-ffcx            0.8.0
fenics-ufl             2024.1.0
(carp) $ 

Do I need to install and/or setup things differently? Please note that I already have a custom PETSc installed on my machine that I needed for openCARP. Could that be an issue? If yes, what is the work around?

There is one last thing which I have not done from the instructions:

conda install -c conda-forge fenics-dolfinx mpich pyvista

Could this be the missing link? I dont use conda at all. What is my best way forward? I use pyenv and poetry and switched away from Conda long time ago.

Thanks in advance
~anoop

You are in a venv called carp. You must disable the virtual environment in order to use dolfinx installed by apt.

Yes I am aware of that. But that is not the main issue. Main issue is how to install fenics-dolfinx without conda?

Also, on the venv, how do I make the venv libraries work with the dolfinx which is outside of the venv?

Thanks

You are installing it through apt, which is correct. Disable the venv to confirm that it is installed and you can import it. You don’t need conda on ubuntu.

My understanding of venv is that it creates an isolated environment. By definition, if you want it to find packages in the global path it wouldn’t be isolated anymore. Most of all, if you already have a PETSc installation in your venv, that will surely mess up dolfinx from the system path.

I did run it outside of the venv also. Even then, these are my current problems

  1. Without conda on ubuntu, just the apt install fenicsx, can not import the dolfinx module
  2. When I install conda and do conda install fenics-dolfinx, it seems to import the dolfinx, but all my other libraries are in the venv, and am struggling to get the two together !

~anoop

I cannot reproduce this with the following lines of code:

FROM ubuntu:24.04

RUN export DEBIAN_FRONTEND=noninteractive && \
    apt-get -qq update && \
    apt-get -yq --with-new-pkgs -o Dpkg::Options::="--force-confold" upgrade && \
    apt-get install -y  software-properties-common && \
    add-apt-repository ppa:fenics-packages/fenics && \
    apt-get update && \
    apt-get install -y python3-venv

RUN export DEBIAN_FRONTEND=noninteractive && \
    apt install -y fenicsx

ENV VIRTUAL_ENV=/dolfinx-env
ENV PATH=/dolfinx-env/bin:$PATH
RUN python3 -m venv dolfinx-env --system-site-packages

I’ve tested this with the commands:

docker build -t test_dx .

and then in turn activated with:

docker run --rm -ti test_dx

Note the crucial flag --system-site-packages

python3 -m venv dolfinx-env --system-site-packages

that allows the virtual env access to system site packages, where the apt installation puts dolfinx.

This is for instance specified in:

Thank you all for your insights. Much appreciated.

It turns out the issue was indeed the local PETSc installation and mpicc I already had. Finally, I decided to get the FEniCSx sources and build with cmake.

This is now working fine on my machine.

$ pip list|grep fenics
fenics-basix      0.9.0.dev0
fenics-dolfinx    0.9.0.dev0
fenics-ffcx       0.9.0.dev0
fenics-ufl        2024.2.0.dev0
$

Now I am running into a new problem. I get the following error:

ModuleNotFoundError: No module named 'dolfinx.cpp.fem.petsc'; 'dolfinx.cpp.fem' is not a package

Indeed the dolfinx.cpp.fem.petsc is referred in dolfinx code from python/dolfinx/fem/petsc.py but I dont see a corresponding dolfinx/cpp/fem/petsc folder.

Do I need to install additional components? or did configure go wrong?

Best regards
~anoop

The dolfinx Python Interface builds bindings from C++. It Seems like you have an incomplete installation of the Python interface.

What were the exact commands you ran, and what were the outputs?

I suspected so too. So did a fresh build again.

Now am getting an error in adios4dolfinx import

Python 3.10.2 (main, Aug 12 2023, 21:20:16) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import adios4dolfinx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anoop/.pyenv/versions/carp/lib/python3.10/site-packages/adios4dolfinx/__init__.py", line 10, in <module>
    from .checkpointing import (
  File "/home/anoop/.pyenv/versions/carp/lib/python3.10/site-packages/adios4dolfinx/checkpointing.py", line 16, in <module>
    from .adios2_helpers import (adios_to_numpy_dtype, read_array, read_cell_perms,
  File "/home/anoop/.pyenv/versions/carp/lib/python3.10/site-packages/adios4dolfinx/adios2_helpers.py", line 11, in <module>
    from .utils import compute_local_range, valid_function_types
  File "/home/anoop/.pyenv/versions/carp/lib/python3.10/site-packages/adios4dolfinx/utils.py", line 66, in <module>
    V: dolfinx.fem.FunctionSpaceBase,
AttributeError: module 'dolfinx.fem' has no attribute 'FunctionSpaceBase'. Did you mean: 'FunctionSpace'?

To answer your other questions, this is how I installed dolfinx python interface

$ cd python
$ pip install -r build-requirements.txt
$ pip install --check-build-dependencies --no-build-isolation .

Have you checked out the relevant branches of DOLFINx, basix, ffcx, ufl and adios4dolfinx?
If you have cloned the repositories then you should be on a consistent set of branches for all of them.
ADIOS4DOLFINx uses the same minor version numbering as DOLFINx.

Yes. I think I have (FEniCSx for sure). Here are the version numbers of my installations

fenics-basix              0.9.0.dev0
fenics-dolfinx            0.9.0.dev0
fenics-ffcx               0.9.0.dev0
fenics-ufl                2024.2.0.dev0

adios4dolfinx was installed as a dependency by another software I am using and it had 0.7.0 version.

I realized after going through the github page of adios4dolfinx, that I need to build MPI version of adios2 which I had not done and nor had I built the adios4dolfinx from sources.

In the process of doing that now and I guess all my concerns are now addressed and I should have everything up and running.

Thanks for your support. Much appreciated.

~anoop

I just had to upgrade the adios4dolfinx from v0.7 to v0.8 and I have a working setup now.

Thanks a bunch
~anoop