============
Installation
============

Use of PyNN_ requires that you have Python and the numpy_ package installed, plus at least one of the supported simulators: NEURON, NEST or PCSIM.


Installing NEURON
=================

Download the sources for the latest release of NEURON, in ``.tar.gz`` format, from `<http://www.neuron.yale.edu/neuron/install/install.html>`_. Also download Interviews from the same location.

Compile Interviews and NEURON according to the instructions given at `<http://www.neuron.yale.edu/neuron/install/compile_unix.html#fullinstall>`_, except that when you run ``configure``, add the options ``--with-nrnpython`` and, optionally, ``--with-mpi`` (the latter assumes you have the MPICH library installed on your machine), i.e.::

    $ ./configure --prefix=`pwd` --with-nrnpython --with-mpi
    $ make
    $ make install

Make sure that you add the Interviews and NEURON bin directories to your path. Test that the Python support has been enabled by running::

    $ nrniv -python
    NEURON -- Release 6.1.2 (1927) 2007-12-30
    Duke, Yale, and the BlueBrain Project -- Copyright 1984-2007
    See http://www.neuron.yale.edu/credits.html

    >>> import hoc
    >>> import nrn   

Now you can compile and install NEURON as a Python package::

    $ cd src/nrnpython
    # python setup.py install

Note that the latter step requires running as root and will install to your global python ``site-packages`` directory.
If you would prefer to install it locally, replace the last step with::

    $ python setup.py install --prefix=~

which will install into ``~/lib/python2.5/site-packages/`` (or the equivalent for other Python versions; for more fine-grained control over where the package is installed, see the `distutils`_ documentation), then add this directory to your ``PYTHONPATH``::

    $ export PYTHONPATH=$PYTHONPATH:~/lib/python2.5/site-packages

Now test everything worked::

    $ python
    >>> import neuron
    NEURON -- Release 6.1.1 (1894) 2007-11-24
    Duke, Yale, and the BlueBrain Project -- Copyright 1984-2007
    See http://www.neuron.yale.edu/credits.html

    >>> 


Installing NEST and PyNEST
==========================

NEST can be downloaded from `<http://www.nest-initiative.org/?page=Software&subpage=Download>`_.
Installation instructions are available in the file INSTALL, which you can find in the source package.

Checkout PyNEST from the following Subversion repository (contact the NEST developers for access)::

    $ svn co svn+ssh://facets@www.nest-initiative.uni-freiburg.de/facets/trunk pynest
    $ cd pynest
    
Set the ``SLIHOME`` environment variable to your NEST source installation and ``SLIBUILD`` to your NEST build directory, e.g. (for bash)::

    $ export SLIHOME=/usr/src/nest-1.0.13
    $ export SLIBUILD=$SLIHOME/build
    
Finally, build and install PyNEST::

    $ python setup.py install
    
This will install it to your python ``site-packages`` directory, and may require root privileges.
If you wish to install it elsewhere::

    $ python setup.py install --prefix=/where/to/install/pynest
    
and then set the ``PYTHONPATH`` environment variable appropriately, e.g.::
    
    $ export PYTHONPATH=$PYTHONPATH:/where/to/install/pynest/lib/python2.4/site-packages/

Now try it out::

    $ cd ~ 
    $ python 
    >>> import pynest 
    >>> pynest.sps([1,2,3]) 
    >>> pynest.spp() 
    [1, 2, 3]


Installing PCSIM
================

PCSIM_ is available by svn as follows:

    $ svn co https://pcsim.svn.sourceforge.net/svnroot/pcsim pcsim

For compilation instructions, see the files in the ``HowTos`` directory.


Installing PyNN
===============

The easiest way to get PyNN is to download the latest source distribution from the `PyNN download page`_, then run the setup script, e.g.::

    $ tar xzf PyNN-0.4.0.tar.gz
    $ cd PyNN-0.4.0
    $ python setup.py install
    
This will install it to your python ``site-packages`` directory, and may require root privileges. If you wish to install it elsewhere use the ``--prefix`` or ``--home`` option, and set the ``PYTHONPATH`` environment variable accordingly (see above).

Test it using something like the following::

    >>> from pyNN.nest1 import *
    >>> setup()
    >>> end()
    
(This assumes you have PyNEST installed).

With NEURON as the simulator, PyNN-specific membrane mechanisms are loaded on `setup()`::
   
    >>> from pyNN.neuron import *
    NEURON -- Release 6.1.1 (1894) 2007-11-24
    Duke, Yale, and the BlueBrain Project -- Copyright 1984-2007
    See http://www.neuron.yale.edu/credits.html

    >>> setup()
    loading membrane mechanisms from /usr/lib/python/site-packages/pyNN/hoc/i686/.libs/libnrnmech.so
    Additional mechanisms from files
     alphaisyn.mod alphasyn.mod expisyn.mod refrac.mod reset.mod stdwa_softlimits.mod
     stdwa_songabbott.mod stdwa_symm.mod vecstim.mod

If your model relies on other NMODL mechanisms, call the `load_mechanisms()` function with the path to the directory containing the ``.mod`` files.

.. _PyNN: http://neuralensemble.org/trac/PyNN
.. _numpy: http://numpy.scipy.org/
.. _PCSIM: http://sourceforge.net/projects/pcsim/
.. _`PyNN download page`: https://neuralensemble.kip.uni-heidelberg.de/trac/PyNN/wiki/Download
.. _`distutils`: http://docs.python.org/inst/inst.html
