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