Page 1 of 1

Finding Neuron install prefix from Python

Posted: Tue Nov 14, 2017 4:19 am
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

Re: Finding Neuron install prefix from Python

Posted: Tue Nov 14, 2017 8:15 am
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.

Re: Finding Neuron install prefix from Python

Posted: Tue Nov 14, 2017 6:30 pm
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.