Finding Neuron install prefix from Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Finding Neuron install prefix from Python

Post by tclose »

Hi,

I have been trying to work out a fail safe way to get the Neuron install prefix, and thereby the path to nrnivmodl, using only the Python Neuron module. Currently I am assuming that it is on the system path (I don't want to have to rely on NRNHOME being set) but this fails if I need to switch between different versions built for Python 2 and 3. Is this possible?

In a similar vein, is there a function for retrieving the Neuron version in PyNeuron?

Thanks,

Tom
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Finding Neuron install prefix from Python

Post by ramcdougal »

To find the install directory use h.neuronhome().
  • This does not require the environment variable to be set, but it returns the value of the environment variable if it is set.
  • The interpretation of the result is slightly system dependent, so be sure to read the documentation.
To find the version use h.nrnversion().
There are different arguments you can pass depending on what version information you want to know:

Code: Select all

>>> for i in range(10):
...     print ('%d : %s' % (i, h.nrnversion(i)))
... 
0 :  7.5
1 :  NEURON -- VERSION 7.5 master (2cbd3b1) 2017-09-08
2 :  VERSION 7.5 master (2cbd3b1)
3 :  2cbd3b1
4 :  2017-09-08
5 :  1646
6 :   '--prefix=/Applications/NEURON-7.5/nrn' '--with-paranrn=dynamic' '--with-nrnpython=dynamic' '--with-pyexe=python3' 'CYTHON=/Users/hines/anaconda2/bin/cython'
7 :  NEURON
8 :  x86_64-apple-darwin16.7.0
9 :  2
Most of these are probably self-explanatory. Argument option 5 is no longer meaningful since it pertained to the hg version number, but we now use git instead of hg. The return value of "2" for h.nrnversion(9) indicates NEURON was launched via python instead of via nrniv -python. This mattered in older versions, because there were certain things that weren't supported if NEURON wasn't the main program (e.g. MovieRun). These limitations have been fixed and it is now most natural to just launch scripts directly via python.

Note that h.nrnversion() always returns a string never an integer.
Last edited by ramcdougal on Sun Nov 26, 2017 8:11 am, edited 1 time in total.
tclose
Posts: 27
Joined: Tue Jan 10, 2017 9:24 pm

Re: Finding Neuron install prefix from Python

Post by tclose »

Thanks Rob. That works a treat. Although the docs may need amending slightly as using h.neuronhome() on macOS I still received the --prefix/nrn/share value, not the bin directory directly. This may be because I installed from source though.
Post Reply