Page 1 of 2

Importing neuron module into Python

Posted: Mon Dec 15, 2014 3:21 pm
by roybens
Hello all,

I am having difficulty importing neuron into python.

After launching python...

Code: Select all

Last login: Mon Dec 15 12:16:56 on ttys000
kjb:~ ken$ cd neuron/nrn/src/nrnpython/
kjb:nrnpython ken$ python
Python 2.7.8 |Anaconda 1.9.0 (x86_64)| (default, Jul  2 2014, 15:36:00) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
I simply try an

Code: Select all

import neuron
command, and am left with this ImportError

Code: Select all

>>> import neuron
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//anaconda/lib/python2.7/site-packages/neuron/__init__.py", line 106, in <module>
    import neuron.hoc
ImportError: dlopen(//anaconda/lib/python2.7/site-packages/neuron/hoc.so, 2): Library not loaded: libreadline.6.2.dylib
  Referenced from: //anaconda/lib/python2.7/site-packages/neuron/hoc.so
  Reason: image not found
>>> 
Similar errors are presented with

Code: Select all

from neuron import h
Any ideas what might be causing this? I did a "find" from the root directory for this "libreadline.6.2.dylib" and couldn't find anything....

Thanks!

Re: Importing neuron module into Python

Posted: Mon Dec 15, 2014 7:16 pm
by ted
Sounds like you need libreadline.6.2.dylib from wherever OS X users get it. I don't know enough about OS X to say any more.

Re: Importing neuron module into Python

Posted: Wed Dec 17, 2014 12:11 pm
by hines
Is anything about readline mentioned when, from a terminal window, you execute
otool -L //anaconda/lib/python2.7/site-packages/neuron/hoc.so

Can you launch nrniv successfully?

Re: Importing neuron module into Python

Posted: Wed Dec 17, 2014 1:12 pm
by roybens
Michael,
Is anything about readline mentioned when, from a terminal window, you execute
otool -L //anaconda/lib/python2.7/site-packages/neuron/hoc.so
The result from that command is as follows (note the "libreadline" about 3/4 the way down):

Code: Select all

kjb:~ ken$ otool -L //anaconda/lib/python2.7/site-packages/neuron/hoc.so
//anaconda/lib/python2.7/site-packages/neuron/hoc.so:
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrnpython1013.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrnoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/liboc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrniv.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libivoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmemacs.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmeschach.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libneuron_gnu.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libscopmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsparse13.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsundials.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	libreadline.6.2.dylib (compatibility version 6.0.0, current version 6.2.0)
   /Users/ken/local/x86_64/lib/libIVhines.3.dylib (compatibility version 4.0.0, current version 4.3.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 283.0.0)
Can you launch nrniv successfully?
Seems so....:

Code: Select all

kjb:~ ken$ nrniv
NEURON -- VERSION 7.4 (1198:03358d02fbc4) 03358d02fbc4
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2014
See http://www.neuron.yale.edu/neuron/credits

oc>

Re: Importing neuron module into Python

Posted: Wed Dec 17, 2014 2:11 pm
by hines
What readline, if any, is referred to when you do a
otool -L `which nrniv`
(note the single backquotes)

Re: Importing neuron module into Python

Posted: Wed Dec 17, 2014 5:17 pm
by roybens
Michael:

I didn't see anything relating to "libreadline.6.2.dylib" this time...

Code: Select all

kjb:~ ken$ otool -L `which nrniv`
/Applications/NEURON-7.3/nrn/x86_64/bin/nrniv:
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrnoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrniv.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libivoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/liboc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/opt/X11/lib/libX11.6.dylib (compatibility version 10.0.0, current version 10.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libneuron_gnu.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libscopmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsparse13.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsundials.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmemacs.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmeschach.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Users/ken/local/x86_64/lib/libIVhines.3.dylib (compatibility version 4.0.0, current version 4.3.0)
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

Re: Importing neuron module into Python

Posted: Thu Dec 18, 2014 2:09 am
by hines
kjb:~ ken$ nrniv
NEURON -- VERSION 7.4 (1198:03358d02fbc4)
Since you must be building from sources, I wonder if you can try an experiment. Edit the nrn/src/nrnpython/setup.py file, search for "readline" and just
remove that line and do a 'make install' (from the nrn folder). Let me know if that fixes the problem. Can you also say exactly what 'configure' line you used to
start the original build process (you can know it from 'grep configure config.status' from the nrn folder).

Re: Importing neuron module into Python

Posted: Fri Dec 19, 2014 3:12 pm
by roybens
Michael,

Commenting out that line did not solve the problem.

The result of the grep command is as follows:

Code: Select all

# Generated by configure.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
configured by ../nrn/configure, generated by GNU Autoconf 2.69,
ac_configure_extra_args=
  ac_configure_extra_args="$ac_configure_extra_args --silent"
  set X /bin/sh '../nrn/configure'  '--prefix=/Applications/NEURON-7.3/nrn' '--with-iv=/Applications/NEURON-7.3/iv' '--with-nrnpython=dynamic' '--with-paranrn=dynamic' $ac_configure_extra_args --no-create --no-recursion
    # on some systems where configure will not decide to define it.
    # Let's still pretend it is `configure' which instantiates (i.e., don't
    configure_input='Generated from '`
	`' by configure.'
      configure_input="$ac_file.  $configure_input"
    case $configure_input in #(
       ac_sed_conf_input=`$as_echo "$configure_input" |
    *) ac_sed_conf_input=$configure_input;;
s|@configure_input@|$ac_sed_conf_input|;t t
      $as_echo "/* $configure_input  */" \
    $as_echo "/* $configure_input  */" \
# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
Again thank you so much for the help!

Re: Importing neuron module into Python

Posted: Sat Dec 20, 2014 2:34 am
by hines
Commenting out that line did not solve the problem.
There is a puzzle here. Here is my understanding of the situation before the last experiment of modifying setup.py
1) otool mentions libreadline in regard to hoc.so and launching python and importing the neuron module does not work since libreadline is missing.
2) otool shows no mention of libreadline in regard to nrniv and launching 'nrniv -python' works fine and you can successfully 'import neuron'.

Now that you have removed the mention of readline in setup.py, what is the result of otool on the new hoc.so file?
By the way, on my mavericks mac, there is no mention of libreadline in either case and I also have a /usr/lib/libreadline.dylib which turns out to be a symbolic
link to /usr/lib/libedit.3.dylib which indeed is mentioned by otool both for hoc.so and nrniv.

Do you have /usr/lib/libedit.3.dylib?

Re: Importing neuron module into Python

Posted: Sat Dec 20, 2014 9:49 am
by roybens
2) otool shows no mention of libreadline in regard to nrniv and launching 'nrniv -python' works fine and you can successfully 'import neuron'.
Yes, this appears to be true... strange.

Code: Select all

Last login: Fri Dec 19 21:36:38 on ttys000
kjb:~ ken$ nrniv -python
NEURON -- VERSION 7.4 (1198:03358d02fbc4) 03358d02fbc4
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2014
See http://www.neuron.yale.edu/neuron/credits

>>> import neuron
>>> from neuron import h
>>> 
The otool result is as follows:

Code: Select all

kjb:~ ken$ otool -L //anaconda/lib/python2.7/site-packages/neuron/hoc.so
//anaconda/lib/python2.7/site-packages/neuron/hoc.so:
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrnpython1013.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrnoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/liboc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libnrniv.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libivoc.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmemacs.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libmeschach.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libneuron_gnu.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libscopmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsparse13.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Applications/NEURON-7.3/nrn/x86_64/lib/libsundials.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	libreadline.6.2.dylib (compatibility version 6.0.0, current version 6.2.0)
	/Users/ken/local/x86_64/lib/libIVhines.3.dylib (compatibility version 4.0.0, current version 4.3.0)
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
	/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 283.0.0)
In /usr/lib/ I have:

Code: Select all

libedit.2.dylib
libedit.3.0.dylib
libedit.3.dylib
libedit.dylib
...
libreadline.dylib
Since that's the only "libreadline" I've found, do you think I should try to download readline? I found this while poking around on Google... http://rudix.org/packages/readline.html

Re: Importing neuron module into Python

Posted: Sat Dec 20, 2014 12:23 pm
by hines
That is the only libreadline on my machine as well. I would try your last dmg suggestion.

Re: Importing neuron module into Python

Posted: Tue Dec 23, 2014 6:51 am
by hines
Does
export DYLD_LIBRARY_PATH=$HOME/anaconda/lib
fix the problem? Are you using the new Yosemite mac os x?

I reproduced the readline problem by upgrading an extra partition on my mac air from Mavericks to Yosimite and installing Anaconda. Also
conda install mayavi
I installed xquartz 2.7.7 and command line tools. To use the latter I had to:
sudo gcc --version
in order to agree to the license.
Nowadays the X11 preferences for windows allows one to select "focus follows mouse" and
"click through inactive windows"
I also installed openmpi-1.8.4 with a last step of 'sudo make install'
After installing openmpi the first time I had problems with some of the shared libraries, maybe from the previous installation, but
rm -r -f /usr/local
and a re-install made it work (but also had to reinstall hg since that was the only other thing in /usr/local.
The latest 7.3 NEURON dmg on the alpha site had no problems with readline but I did need a
export LD_LIBRARY_PATH=$HOME/anaconda/lib
so that nrniv -python would import spicy, etc.

I built the 7.4 version from the latest repository sources using:
../nrn/configure --prefix=/Applications/NEURON-7.4/nrn --with-paranrn=dynamic --with-nrnpython=dynamic BUILD_RX3D=0 have_cython=no --with-readline=no
Without the rx3d and cython args the install seemed to hang at compiling ctng but I'll deal with that later.

For some unknown and puzzling reason, various attempts to solve the readline problem using LD_LIBRARY_PATH and copying $HOME/anaconda/lib/libreadline.6.2.dylib to various places within the NEURON installation folder did not fix the problem. But using
DYLD_LIBRARY_PATH fixed the problem. The only questionable aspect of this is that I don't know that you are using Yosimite and that you explicitly stated that
libreadline.6.2.dylib was not on your machine whereas on my machine I see
Michaels-MacBook-Air:anaconda hines$ find . -name libreadline\*
./lib/libreadline.6.2.dylib
./lib/libreadline.6.dylib
./lib/libreadline.a
./lib/libreadline.dylib
./pkgs/readline-6.2-2/lib/libreadline.6.2.dylib
./pkgs/readline-6.2-2/lib/libreadline.6.dylib
./pkgs/readline-6.2-2/lib/libreadline.a
./pkgs/readline-6.2-2/lib/libreadline.dylib

Re: Importing neuron module into Python

Posted: Wed Dec 24, 2014 8:21 am
by roybens
Hi Michael,

Yes I am using Yosemite. I think I found a temporary solution!

When I do a "find . -name libreadline.6.2\*" from the root directory I now find it (I assume it's because of the dmg install I recently did):

Code: Select all

./anaconda/lib/libreadline.6.2.dylib
./anaconda/pkgs/readline-6.2-2/lib/libreadline.6.2.dylib
./usr/local/octave/3.8.0/lib/libreadline.6.2.dylib
Therefore I tweaked your suggestion to change the path to /anaconda/lib (not $HOME/anaconda/lib, which did not work) and this seems to work for now:

Code: Select all

kjb:/ ken$ export DYLD_LIBRARY_PATH=/anaconda/lib
kjb:/ ken$ python
'Python 2.7.8 |Anaconda 1.9.0 (x86_64)| (default, Jul  2 2014, 15:36:00) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import neuron
NEURON -- VERSION 7.4 (1198:03358d02fbc4) 03358d02fbc4
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2014
See http://www.neuron.yale.edu/neuron/credits

>>> 
This export is not permanent right? I think I'd have to add it to my .bashrc file?

Also does this seem like we've addressed the issue sufficiently or does this hack worry you?

Thanks!
Ken

Re: Importing neuron module into Python

Posted: Wed Dec 24, 2014 9:55 am
by hines
This export is not permanent right? I think I'd have to add it to my .bashrc file?
correct.
addressed the issue sufficiently or does this hack worry you?
Environment variables are fine. This is one more of a half dozen cases where they are needed. To avoid problems in the future, I am working
on wrapping nrniv in a shell script that embodies all the strange issues of which am aware and sets, if needed,
PYTHONPATH, PYTHONHOME, LD_LIBRARY_PATH, and now DYLD_LIBRARY_PATH. Without being an expert in mac os x environment policies, I can't help but
think that the DYLD_LIBRARY_PATH requirement is a bug in the os. It seems to me that LD_LIBRARY_PATH should have worked.

Re: Importing neuron module into Python

Posted: Sun Dec 28, 2014 11:44 am
by aaronmil
I also encountered this issue after compiling neuron from source with anaconda python. I resolved it by copying libreadline.6.2.dylib from /anaconda/lib into /usr/lib