Wrong candidate paths to find PETSc shared library

Hi everyone,

I am attempting to install dolfinx following the instructions provided here:https://docs.fenicsproject.org/dolfinx/. However, I cannot use conda (due to company restrictions and the need for a license), and using apt results in an SSL certificate error (I am using WSL in a Windows computer protected by a cloud security platform (Zscaler)).

When I run from dolfinx import default_real_type, fem, mesh, I encounter the following error:

File "/home/tcousin/turb_env/lib/python3.12/site-packages/dolfinx/__init__.py", line 32, in <module>
    from dolfinx import fem, geometry, graph, io, jit, la, log, mesh, nls, plot, utils
  File "/home/tcousin/turb_env/lib/python3.12/site-packages/dolfinx/utils.py", line 115, in <module>
    class ctypes_utils:
  File "/home/tcousin/turb_env/lib/python3.12/site-packages/dolfinx/utils.py", line 136, in ctypes_utils
    _lib_ctypes = _ctypes.cdll.LoadLibrary(str(get_petsc_lib()))

And the error message continues with:

File "/home/tcousin/turb_env/lib/python3.12/site-packages/dolfinx/utils.py", line 44, in get_petsc_lib
    raise RuntimeError(
RuntimeError: Could not find a PETSc shared library. Candidate paths: ['/tmp/pip-build-env-7cnfg82c/normal/lib/python3.12/site-packages/petsc/lib/libpetsc.so', '/tmp/pip-build-env-7cnfg82c/normal/lib/python3.12/site-packages/petsc/lib/libpetsc.dylib']

I don’t understand where these candidate paths are coming from. When I run find / -name "libpetsc.so", it returns the following path:

/home/tcousin/turb_env/lib/python3.12/site-packages/petsc/lib/libpetsc.so.

How can I make this path the “candidate” path for PETSc?

Thanks a lot for your time and for this amazing platform.

You are linking to the general installation instructions. Do you mean that you are using the apt installation method: dolfinx/README.md at main · FEniCS/dolfinx · GitHub
inside WSL?

Since it seems like you are using a virtual environment:

you would need to be more specific, i.e. as in specifying how you install PETSc and DOLFINx, and what the $PETSC_DIR and $PETSC_ARCH variables are set to.

You are linking to the general installation instructions. Do you mean that you are using the apt installation method: dolfinx/README.md at main · FEniCS/dolfinx · GitHub
inside WSL?

No, the apt installation needs add-apt-repository ppa:fenics-packages/fenics, leading to ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000) in my case.

I am following the “From source” installation, with all the dependencies needed, listed in https://docs.fenicsproject.org/dolfinx/main/python/installation.html. During the python dependencies I install petsc4py (pip install petsc4py) and then final Dolfinx installation
pip install -r build-requirements.txt
pip install --check-build-dependencies --no-build-isolation .

It works perfectly:
DOLFINx has now been installed in /usr/local

The problem occurs when I try to run a small example code.

echo $PETSC_DIR && echo $PETSC_ARCH gives me nothing. The error might comes from this ?

You should install PETSc before compiling the C++ backend.
Simply having the DOLFINx python interface linked to petsc4py won’t give you the full feature-set of DOLFINx.

See for instance:

on how to compile PETSc
and

on how to install petsc4py.

I tried with PETSc intalled before following these lines:

# Install PETSc and petsc4py with real and complex types
ENV PETSC_DIR=/usr/local/petsc SLEPC_DIR=/usr/local/slepc
RUN apt-get -qq update && \
    apt-get -y install bison flex && \
    git clone --depth=1 -b v${PETSC_VERSION} https://gitlab.com/petsc/petsc.git ${PETSC_DIR} && \

but nothing changed after Dolfinx installation, I still have these wrong candidate paths.
Thanks for your help anyway!

Please add the output of this he compilation of both dolfinx C++ and the Python interface. Without them it is hard to give any guidance.

Please note that the «easiest» way to install from source is to use spack.