NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post Reply
rgerkin
Posts: 5
Joined: Fri Oct 06, 2017 11:38 am

NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post by rgerkin » Tue Oct 17, 2017 11:36 am

Since the instructions on the webpage didn't work for me, I want to document here commands that allowed me to install NEURON 7.5 from source with Python 3 support on OSX 10.12.5. I hope this will be useful to someone.

For simplicity, this installation excludes Interviews, MPI support, and everything else you don't really need if you just want to use NEURON to compile and run serial simulations. I may edit this in the future should the need arise.

1) Put this in your ~/.bash_profile and then start a new shell

Code: Select all

export PYTHONHOME=/path/to/your/python3 # For me it was /Users/rgerkin/miniconda3
export NEURON_HOME=/Applications/NEURON-7.5
export LD_LIBRARY_PATH=$PYTHONHOME/lib
export PATH=$PATH:$NEURON_HOME/nrn/x86_64/bin
export PYTHONPATH=$PYTHONPATH:$NEURON_HOME/nrn/lib/python/
2) Cleanup stuff

Code: Select all

rm -rf $NEURON_HOME # Get rid of old NEURON installations
rm -rf $PYTHONHOME/lib/site-packages/neuron # Get rid old old NEURON code installations
3) Use Python 2 to install mercurial since it is one of the 1% of things that still doesn't work in Python 3

Code: Select all

export PYTHON2 = /path/to/your/python2
$PYTHON2/bin/pip install mercurial
4) Download and install NEURON

Code: Select all

$PYTHON2/bin/hg clone http://www.neuron.yale.edu/hg/neuron/nrn
cd nrn
sh build.sh
./configure --prefix=$NEURON_HOME/nrn --with-nrnpython=python3 # don't use "dynamic" since it doesn't actually work
make
sudo make install
5) Test your installation

Code: Select all

nrniv
python -c "import neuron"
Note: You are likely to get a segmentation fault (this has happened on 3 Macs with various installations of NEURON) if you try importing NEURON anywhere other than the very top of your python program. For example, if you are in an interpreter, let "import neuron" be your *very first* command. Then other "import neuron" commands in your scripts will just be ignored as the module will already be loaded.

ted
Site Admin
Posts: 5091
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post by ted » Wed Oct 18, 2017 4:13 pm

One comment: get the source code from the github repository
git clone https://github.com/nrnhines/iv.git
git clone https://github.com/nrnhines/nrn.git

rgerkin
Posts: 5
Joined: Fri Oct 06, 2017 11:38 am

Re: NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post by rgerkin » Tue Oct 24, 2017 2:21 am

Thanks, Ted. This is also probably a good idea since setting the PYTHONHOME environment variable, which I think NEURON needs for installation if not for execution, can screw up the version of python that it is not set to. Which means that in the example above Python2 can get screwed up and so best to avoid the need for it at all in these Python3-centric instructions.

rgerkin
Posts: 5
Joined: Fri Oct 06, 2017 11:38 am

Re: NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post by rgerkin » Tue Oct 31, 2017 12:04 am

I've created a minimal installation verified using Travis CI and tested against a simple example from the Neuron website.
https://github.com/rgerkin/neuron-python3-miniconda

rgerkin
Posts: 5
Joined: Fri Oct 06, 2017 11:38 am

Re: NEURON 7.5 + Python 3 installation on OSX 10.12.5

Post by rgerkin » Fri Nov 10, 2017 2:31 am

For simple NEURON scripts like the one in https://neuron.yale.edu/neuron/static/d ... steps.html, the instructions I gave seem to work, but for others I run into:

Code: Select all

dyld: Library not loaded: @rpath/libpython3.5m.dylib
I can fix this with:

Code: Select all

sudo install_name_tool -change @rpath/libpython3.5m.dylib $MC3/lib/libpython3.5m.dylib $NEURON_HOME/bin/nrniv
where MC3 is the path to my Python installation (Miniconda3), but this is crude hack and I have to do each time I recompile NEURON. What is the correct flag or environment variable to set to make NEURON see my libpython3.5m library? I tried setting LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, and various compiler flags and none of them seemed to work. Each time the nrniv binary was still looking for @rpath/libpython3.5m.dylib and I had to hack the binary as described above to fix it.

Post Reply