xref: /petsc/src/binding/petsc4py/docs/source/install.rst (revision 046f22ae4f3a0588d5e7db76d29d6e49505e63d4)
1Installation
2============
3.. _petsc4py_install:
4
5
6Using **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 [--user] numpy mpi4py  (or pip install [--user] numpy mpi4py)
13  $ python -m pip install [--user] petsc petsc4py (or pip install [--user] petsc petsc4py)
14
15
16From PETSc source
17-----------------
18
19If you already have downloaded PETSc source and have installed the dependencies
20of `petsc4py`, then to build the `petsc4py` module along with PETSc, add the
21`--with-petsc4py=1` argument to the configure command when building PETSc:
22
23  $ ./configure --with-petsc4py=1
24  $ make
25  $ make install
26
27This will install PETSc and the `petsc4py` module into the PETSc directory
28under the prefix specified to the PETSc configure command.
29
30If you wish to make the module importable without having to set the
31`PYTHONPATH` environment variable, you may add a shortcut to the system-wide
32`site-packages` directory creating a special `.pth` file with exactly one line
33of Python code. This can be done by the following command, where the
34system-wide path is assumed to be `/usr/lib/pythonX/site-packages` (replace `X`
35with your python version):
36
37  $ echo \
38    "import sys, os;" \
39    "p = os.getenv('PETSC_DIR');" \
40    "a = os.getenv('PETSC_ARCH') or '';" \
41    "p = p and os.path.join(p, a, 'lib');" \
42    "p and (p in sys.path or sys.path.append(p))" \
43    > /usr/lib/pythonX/site-packages/petsc4py.pth
44