Unable to find Petsc library after ubuntu installation

Attempting to run demo_poisson after apt-install in Ubuntu with WSL. It seems necessary packages didn’t install? I receive this error, and am not sure where to start troubleshooting

Traceback (most recent call last):
  File "/home/.../demo_poisson.py", line 70, in <module>
    import dolfinx
  File "/home/.../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/.../python3.12/site-packages/dolfinx/utils.py", line 115, in <module>
    class ctypes_utils:
  File "/home/.../python3.12/site-packages/dolfinx/utils.py", line 136, in ctypes_utils
    _lib_ctypes = _ctypes.cdll.LoadLibrary(str(get_petsc_lib()))
                                               ^^^^^^^^^^^^^^^
  File "/home/.../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-7rtr6ii0/normal/lib/python3.12/site-packages/petsc/lib/libpetsc.so', '/tmp/pip-build-env-7rtr6ii0/normal/lib/python3.12/site-packages/petsc/lib/libpetsc.dylib']

Your error message references /home. It looks like you haven’t used apt to install dolfinx.

1 Like

Just to be sure, I uninstalled and reinstalled, definitely using apt.
When I type whereis dolfinx I get dolfinx: /usr/local/lib/dolfinx /usr/include/dolfinx /usr/share/dolfinx. when I type whereis python3, I get python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3. /home is still showing up in the error traceback when I run demo_poisson though.

Edit for anyone who comes across this in the future - I somehow had a second installation of python in /home. Removing that instance fixed the issue

1 Like