ModuleNotFoundError: No module named 'PetscBinaryIO'

Hello,
I am trying to read back an XDMF file with time series that I had been created lately. From other topics I figured out using PetscBinaryIO is the right way. But I get the error:
ModuleNotFoundError: No module named ‘PetscBinaryIO’
So far I have tried pip, conda and homebrew for installing petsc and petsc4py in vain. Am I doing something wrong or should I install it through building source code or something?
I appreciate any tips. Thank you in advance.

The path to PetscBinaryIO.py depends on your petsc installation.
If you are using Docker with ghcr.io/fenics/dolfinx/dolfinx:stable
it is located at: /usr/local/petsc/lib/petsc/bin/PetscBinaryIO.py,
thus appending to the Python-path with export PYTHONPATH=/usr/local/petsc/lib/petsc/bin/:${PYTHONPATH} would resolve your issue.

1 Like

PETSc installations can typically be managed via the environment variable PETSC_DIR. So if PETSC_DIR is appropriately defined, then the path that dokken identified can be written as $PETSC_DIR/lib/petsc/bin

2 Likes