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 16*e079f792SAlexei ColinUsing **setuptools** 17*e079f792SAlexei Colin-------------------- 18*e079f792SAlexei Colin 19*e079f792SAlexei ColinYou can also install dependencies manually and then invoke setuptools 20*e079f792SAlexei Colinfrom the `petsc4py` source directory: 21*e079f792SAlexei Colin 22*e079f792SAlexei Colin $ python setup.py build 23*e079f792SAlexei Colin $ python setup.py install 24*e079f792SAlexei Colin 25*e079f792SAlexei ColinYou may use the `--install-lib` argument to the `install` command to alter the 26*e079f792SAlexei Colin`site-packages` directory where the package is to be installed. 27*e079f792SAlexei Colin 28*e079f792SAlexei Colin 29e8c4a563SAlexei ColinFrom PETSc source 30e8c4a563SAlexei Colin----------------- 315808f684SSatish Balay 32e8c4a563SAlexei ColinIf you already have downloaded PETSc source and have installed the dependencies 33e8c4a563SAlexei Colinof `petsc4py`, then to build the `petsc4py` module along with PETSc, add the 34e8c4a563SAlexei Colin`--with-petsc4py=1` argument to the configure command when building PETSc: 355808f684SSatish Balay 36e8c4a563SAlexei Colin $ ./configure --with-petsc4py=1 37e8c4a563SAlexei Colin $ make 38e8c4a563SAlexei Colin $ make install 39e8c4a563SAlexei Colin 40e8c4a563SAlexei ColinThis will install PETSc and the `petsc4py` module into the PETSc directory 41e8c4a563SAlexei Colinunder the prefix specified to the PETSc configure command. 42046f22aeSAlexei Colin 43046f22aeSAlexei ColinIf you wish to make the module importable without having to set the 44046f22aeSAlexei Colin`PYTHONPATH` environment variable, you may add a shortcut to the system-wide 45046f22aeSAlexei Colin`site-packages` directory creating a special `.pth` file with exactly one line 46046f22aeSAlexei Colinof Python code. This can be done by the following command, where the 47046f22aeSAlexei Colinsystem-wide path is assumed to be `/usr/lib/pythonX/site-packages` (replace `X` 48046f22aeSAlexei Colinwith your python version): 49046f22aeSAlexei Colin 50046f22aeSAlexei Colin $ echo \ 51046f22aeSAlexei Colin "import sys, os;" \ 52046f22aeSAlexei Colin "p = os.getenv('PETSC_DIR');" \ 53046f22aeSAlexei Colin "a = os.getenv('PETSC_ARCH') or '';" \ 54046f22aeSAlexei Colin "p = p and os.path.join(p, a, 'lib');" \ 55046f22aeSAlexei Colin "p and (p in sys.path or sys.path.append(p))" \ 56046f22aeSAlexei Colin > /usr/lib/pythonX/site-packages/petsc4py.pth 57