15808f684SSatish BalayInstallation 25808f684SSatish Balay============ 3eaf87d4bSBarry Smith.. _petsc4py_install: 45808f684SSatish Balay 5eaf87d4bSBarry Smith 6eaf87d4bSBarry SmithUsing **pip** 7eaf87d4bSBarry Smith------------- 85808f684SSatish Balay 95808f684SSatish BalayYou can use :program:`pip` to install :mod:`petsc4py` and its 105808f684SSatish Balaydependencies (:mod:`mpi4py` is optional but highly recommended):: 115808f684SSatish Balay 12eaf87d4bSBarry Smith $ python -m pip install [--user] numpy mpi4py (or pip install [--user] numpy mpi4py) 13eaf87d4bSBarry Smith $ python -m pip install [--user] petsc petsc4py (or pip install [--user] petsc petsc4py) 145808f684SSatish Balay 155808f684SSatish Balay 16e8c4a563SAlexei ColinFrom PETSc source 17e8c4a563SAlexei Colin----------------- 185808f684SSatish Balay 19e8c4a563SAlexei ColinIf you already have downloaded PETSc source and have installed the dependencies 20e8c4a563SAlexei Colinof `petsc4py`, then to build the `petsc4py` module along with PETSc, add the 21e8c4a563SAlexei Colin`--with-petsc4py=1` argument to the configure command when building PETSc: 225808f684SSatish Balay 23e8c4a563SAlexei Colin $ ./configure --with-petsc4py=1 24e8c4a563SAlexei Colin $ make 25e8c4a563SAlexei Colin $ make install 26e8c4a563SAlexei Colin 27e8c4a563SAlexei ColinThis will install PETSc and the `petsc4py` module into the PETSc directory 28e8c4a563SAlexei Colinunder the prefix specified to the PETSc configure command. 29*046f22aeSAlexei Colin 30*046f22aeSAlexei ColinIf you wish to make the module importable without having to set the 31*046f22aeSAlexei Colin`PYTHONPATH` environment variable, you may add a shortcut to the system-wide 32*046f22aeSAlexei Colin`site-packages` directory creating a special `.pth` file with exactly one line 33*046f22aeSAlexei Colinof Python code. This can be done by the following command, where the 34*046f22aeSAlexei Colinsystem-wide path is assumed to be `/usr/lib/pythonX/site-packages` (replace `X` 35*046f22aeSAlexei Colinwith your python version): 36*046f22aeSAlexei Colin 37*046f22aeSAlexei Colin $ echo \ 38*046f22aeSAlexei Colin "import sys, os;" \ 39*046f22aeSAlexei Colin "p = os.getenv('PETSC_DIR');" \ 40*046f22aeSAlexei Colin "a = os.getenv('PETSC_ARCH') or '';" \ 41*046f22aeSAlexei Colin "p = p and os.path.join(p, a, 'lib');" \ 42*046f22aeSAlexei Colin "p and (p in sys.path or sys.path.append(p))" \ 43*046f22aeSAlexei Colin > /usr/lib/pythonX/site-packages/petsc4py.pth 44