Installation of NEURON with Python
These instructions are for NEURON v6.1. They may remain valid for future versions, but will not work with previous versions. The instructions are also for Linux using the bash shell. They may well work on Mac OSX or in Cygwin, but I haven't tested them.
Binary versions of NEURON 6.1 do come with Python support, and allow you to run nrniv -python, but I'm not sure if they allow you to run Python (or IPython) and then do import neuron, so I will go through the process of compiling from source.
First build and install Interviews, if you don't already have it:
$ N=`pwd` $ tar xzf iv-17.tar.gz $ cd iv-17 $ ./configure --prefix=`pwd` $ make $ make install
Now build and install NEURON:
$ cd .. $ tar xzf nrn-6.1.tar.gz $ cd nrn-6.1 $ ./configure --prefix=`pwd` --with-iv=$N/iv-17 --with-nrnpython $ make $ make install
If you want to run parallel NEURON, add --with-paranrn to the configure options. You will also need to use a more recent version of NEURON (from the Subversion repository), since there is a bug in 6.1 which prevents parallel NEURON and Python working properly together.
Now add the NEURON bin directory to your PATH:
$ export PATH=$N/nrn-6.1/i686/bin:$PATH
(Replace i686 with your own CPU architecture if necessary).
Now build the NEURON shared library for Python:
$ cd src/nrnpython # python setup.py install
This command (which will probably have to be run as root or using sudo) will install the neuron package to your site-packages directory. An alternative, especially if you don't have root privileges, is:
$ python setup.py install --prefix=~
which will install the neuron package to ~/lib/python/site-packages. You will then have to add this directory to the PYTHONPATH environment variable:
$ export PYTHONPATH=$PYTHONPATH:~/lib/python/site-packages
Starting NEURON
For those who are not familiar with NEURON, it may be started without the graphical interface using nrniv or with the graphical interface using nrngui. To use Python, rather than hoc, as the interpreter, use the -python option:
$ nrniv -python 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 >>> import neuron >>>
If there are any NEURON extension (NMODL) mechanisms in the working directory, and they have been compiled with nrnivmodl, they will be loaded automatically.
Alternatively, you may wish to use the normal Python interpreter, or an alternative such as IPython. In this case, NEURON is started (and any NMODL mechanisms loaded) when you import neuron:
$ ipython Python 2.4.1 (#1, May 25 2007, 17:56:29) Type "copyright", "credits" or "license" for more information. IPython 0.6.15 -- An enhanced Interactive Python. ? -> Introduction to IPython's features. %magic -> Information about IPython's 'magic' % functions. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: import neuron 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 In [2]:
