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