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 28If you are cross-compiling, and the `numpy` module cannot be loaded on your 29build host, then before invoking `setup.py`, set `NUMPY_INCLUDE` environment 30variable to the path that would be returned by `import numpy; 31numpy.get_include()`: 32 33 $ export NUMPY_INCLUDE=/usr/lib/pythonX/site-packages/numpy/core/include 34 35 36From PETSc source 37----------------- 38 39If you already have downloaded PETSc source and have installed the dependencies 40of `petsc4py`, then to build the `petsc4py` module along with PETSc, add the 41`--with-petsc4py=1` argument to the configure command when building PETSc: 42 43 $ ./configure --with-petsc4py=1 44 $ make 45 $ make install 46 47This will install PETSc and the `petsc4py` module into the PETSc directory 48under the prefix specified to the PETSc configure command. 49 50If you wish to make the module importable without having to set the 51`PYTHONPATH` environment variable, you may add a shortcut to the system-wide 52`site-packages` directory creating a special `.pth` file with exactly one line 53of Python code. This can be done by the following command, where the 54system-wide path is assumed to be `/usr/lib/pythonX/site-packages` (replace `X` 55with your python version): 56 57 $ echo \ 58 "import sys, os;" \ 59 "p = os.getenv('PETSC_DIR');" \ 60 "a = os.getenv('PETSC_ARCH') or '';" \ 61 "p = p and os.path.join(p, a, 'lib');" \ 62 "p and (p in sys.path or sys.path.append(p))" \ 63 > /usr/lib/pythonX/site-packages/petsc4py.pth 64 65If you are cross-compiling, and `numpy` cannot be loaded on your build host, 66then pass `--have-numpy=1 --with-numpy-include=PATH`, where `PATH` is the path 67that would be returned by `import numpy; print(numpy.get_include())`. This will 68suppress autodetection of the include path on the build host. 69