Installation#

Install from PyPI using pip#

You can use pip to install petsc4py and its dependencies (mpi4py is optional but highly recommended):

$ python -m pip install mpi4py petsc petsc4py

Install from the PETSc source tree#

First build PETSc. Next cd to the top of the PETSc source tree and set the PETSC_DIR and PETSC_ARCH environment variables. Run:

$ python -m pip install src/binding/petsc4py

The installation of petsc4py supports multiple PETSC_ARCH in the the form of colon separated list:

$ PETSC_ARCH='arch-0:...:arch-N' python -m pip install src/binding/petsc4py

If you are cross-compiling, and the numpy module cannot be loaded on your build host, then before invoking pip, set the NUMPY_INCLUDE environment variable to the path that would be returned by import numpy; numpy.get_include():

$ export NUMPY_INCLUDE=/usr/lib/pythonX/site-packages/numpy/core/include

Building the documentation#

Install the documentation dependencies using the [doc] extra:

$ python -m pip install "src/binding/petsc4py[doc]"

Then:

$ cd src/binding/petsc4py/docs/source
$ make html

The resulting HTML files will be in _build/html.

Note

Building the documentation requires Python 3.11 or later.

Note

All new code must include documentation in accordance with the documentation standard