xref: /petsc/src/binding/petsc4py/docs/source/install.rst (revision d7bfff7c43d7f975edee7f310770eeb28757e48d)
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
16Using **setuptools**
17--------------------
18
19You can also install dependencies manually and then invoke setuptools
20from the `petsc4py` source directory:
21
22  $ python setup.py build
23  $ python setup.py install
24
25You may use the `--install-lib` argument to the `install` command to alter the
26`site-packages` directory where the package is to be installed.
27
28
29From PETSc source
30-----------------
31
32If you already have downloaded PETSc source and have installed the dependencies
33of `petsc4py`, then to build the `petsc4py` module along with PETSc, add the
34`--with-petsc4py=1` argument to the configure command when building PETSc:
35
36  $ ./configure --with-petsc4py=1
37  $ make
38  $ make install
39
40This will install PETSc and the `petsc4py` module into the PETSc directory
41under the prefix specified to the PETSc configure command.
42
43If you wish to make the module importable without having to set the
44`PYTHONPATH` environment variable, you may add a shortcut to the system-wide
45`site-packages` directory creating a special `.pth` file with exactly one line
46of Python code. This can be done by the following command, where the
47system-wide path is assumed to be `/usr/lib/pythonX/site-packages` (replace `X`
48with your python version):
49
50  $ echo \
51    "import sys, os;" \
52    "p = os.getenv('PETSC_DIR');" \
53    "a = os.getenv('PETSC_ARCH') or '';" \
54    "p = p and os.path.join(p, a, 'lib');" \
55    "p and (p in sys.path or sys.path.append(p))" \
56    > /usr/lib/pythonX/site-packages/petsc4py.pth
57