xref: /petsc/src/binding/petsc4py/docs/source/install.rst (revision 97276fddab9e156c6aa2d4453777ea460476b6f0)
1Installation
2============
3.. _petsc4py_install:
4
5
6Install from PyPI using **pip**
7-------------------------------
8
9You can use :program:`pip` to install :mod:`petsc4py` and its
10dependencies (:mod:`mpi4py` is optional but highly recommended)::
11
12  $ python -m pip install mpi4py petsc petsc4py
13
14Install from the PETSc source tree
15----------------------------------
16
17First `build PETSc <petsc:doc_install>`. Next :file:`cd` to the top of the
18PETSc source tree and set the `PETSC_DIR <petsc:doc_multi>` and `PETSC_ARCH
19<petsc:doc_multi>` environment variables. Run::
20
21  $ python -m pip install src/binding/petsc4py
22
23The installation of :mod:`petsc4py` supports multiple `PETSC_ARCH
24<petsc:doc_multi>` in the form of colon separated list::
25
26  $ PETSC_ARCH='arch-0:...:arch-N' python -m pip install src/binding/petsc4py
27
28If you are cross-compiling, and the :mod:`numpy` module cannot be loaded on
29your build host, then before invoking :program:`pip`, set the
30:envvar:`NUMPY_INCLUDE` environment variable to the path that would be returned
31by :samp:`import numpy; numpy.get_include()`::
32
33  $ export NUMPY_INCLUDE=/usr/lib/pythonX/site-packages/numpy/core/include
34
35Running the testing suite
36-------------------------
37
38When installing from source, the petsc4py complete testsuite can be run as::
39
40  $ cd src/binding/petsc4py
41  $ python test/runtests.py
42
43or via the makefile rule ``test``::
44
45  $ make test -C src/binding/petsc4py
46
47Specific tests can be run using the command-line option ``-k``, e.g.::
48
49  $ python test/runtests.py -k test_optdb
50
51to run all the tests provided in :file:`tests/test_optdb.py`.
52
53For other command-line options, run::
54
55  $ python test/runtests.py --help
56
57If not otherwise specified, all tests will be run in sequential mode.
58To run all the tests with the same number of MPI processes, for example
59``4``, run::
60
61  $ mpiexec -n 4 python test/runtests.py
62
63or::
64
65  $ make test-4 -C src/binding/petsc4py
66
67Building the documentation
68--------------------------
69
70Install the documentation dependencies::
71
72  $ python -m pip install -r ${PETSC_DIR/doc/requirements.txt
73
74Then::
75
76  $ cd src/binding/petsc4py/docs/source
77  $ make html
78
79The resulting HTML files will be in :file:`_build/html`.
80
81.. note::
82
83  Building the documentation requires Python 3.11 or later.
84