xref: /petsc/src/binding/petsc4py/docs/source/install.rst (revision d7cc930e14e615e9907267aaa472dd0ccceeab82)
1Installation
2============
3
4Using **pip** or **easy_install**
5---------------------------------
6
7You can use :program:`pip` to install :mod:`petsc4py` and its
8dependencies (:mod:`mpi4py` is optional but highly recommended)::
9
10  $ pip install [--user] numpy mpi4py
11  $ pip install [--user] petsc petsc4py
12
13Alternatively, you can use :program:`easy_install` (deprecated)::
14
15  $ easy_install petsc4py
16
17If you already have a working PETSc installation, set environment
18variables :envvar:`PETSC_DIR` and :envvar:`PETSC_ARCH` to appropriate
19values and next use :program:`pip`::
20
21  $ export PETSC_DIR=/path/to/petsc
22  $ export PETSC_ARCH=arch-linux2-c-opt
23  $ pip install petsc4py
24
25
26Using **distutils**
27-------------------
28
29Requirements
30^^^^^^^^^^^^
31
32You need to have the following software properly installed in order to
33build *PETSc for Python*:
34
35* Any MPI_ implementation [#]_ (e.g., MPICH_ or `Open MPI`_),
36  built with shared libraries.
37
38* A matching version of PETSc_ built with shared libraries.
39
40* NumPy_ package.
41
42.. [#] Unless you have appropiatelly configured and built PETSc
43       without MPI (configure option ``--with-mpi=0``).
44
45.. [#] You may need to use a parallelized version of the Python
46       interpreter with some MPI-1 implementations (e.g. MPICH1).
47
48.. include:: links.txt
49
50Downloading
51^^^^^^^^^^^
52
53The *PETSc for Python* package is available for download at the
54Python Package Index. You can use
55:program:`curl` or :program:`wget` to get a release tarball.
56
57* Using :program:`curl`::
58
59    $ curl -LO https://pypi.io/packages/source/p/petsc4py/petsc4py-X.Y.Z.tar.gz
60
61* Using :program:`wget`::
62
63    $ wget https://pypi.io/packages/source/p/petsc4py/petsc4py-X.Y.Z.tar.gz
64
65Building
66^^^^^^^^
67
68After unpacking the release tarball::
69
70  $ tar -zxf petsc4py-X.Y.Z.tar.gz
71  $ cd petsc4py-X.Y.Z
72
73the distribution is ready for building.
74
75.. note:: **Mac OS X** users employing a Python distribution built
76   with **universal binaries** may need to set the environment
77   variables :envvar:`MACOSX_DEPLOYMENT_TARGET`, :envvar:`SDKROOT`,
78   and :envvar:`ARCHFLAGS` to appropriate values. As an example,
79   assume your Mac is running **Snow Leopard** on a **64-bit Intel**
80   processor and you want to override the hard-wired cross-development
81   SDK in Python configuration, your environment should be modified
82   like this::
83
84     $ export MACOSX_DEPLOYMENT_TARGET=10.6
85     $ export SDKROOT=/
86     $ export ARCHFLAGS='-arch x86_64'
87
88Some environment configuration is needed to inform the location of
89PETSc. You can set (using :command:`setenv`, :command:`export` or what
90applies to you shell or system) the environment variables
91:envvar:`PETSC_DIR`, and :envvar:`PETSC_ARCH` indicating where you
92have built/installed PETSc::
93
94  $ export PETSC_DIR=/usr/local/petsc
95  $ export PETSC_ARCH=arch-linux2-c-opt
96
97Alternatively, you can edit the file :file:`setup.cfg` and provide the
98required information below the ``[config]`` section::
99
100  [config]
101  petsc_dir  = /usr/local/petsc
102  petsc_arch = arch-linux2-c-opt
103  ...
104
105Finally, you can build the distribution by typing::
106
107  $ python setup.py build
108
109Installing
110^^^^^^^^^^
111
112After building, the distribution is ready for installation.
113
114If you have root privileges (either by log-in as the root user of by
115using :command:`sudo`) and you want to install *PETSc for Python* in
116your system for all users, just do::
117
118  $ python setup.py install
119
120The previous steps will install the :mod:`petsc4py` package at standard
121location :file:`{prefix}/lib/python{X}.{Y}/site-packages`.
122
123If you do not have root privileges or you want to install *PETSc for
124Python* for your private use, just do::
125
126  $ python setup.py install --user
127