Installation Help: Fail to "import neuron" in Python

Post Reply
byronprice
Posts: 3
Joined: Wed Mar 18, 2020 7:18 pm

Installation Help: Fail to "import neuron" in Python

Post by byronprice » Thu Mar 19, 2020 12:42 pm

I'm running MacOS High Sierra 10.13.6. I've setup an Anaconda environment where I'm trying to get Neuron running with Python 3.7. I've almost certainly messed up something up with the PATH and where Python is looking for Neuron. I've seen a few similar errors on here, but haven't found a solution that works.

I've got everything running well enough such that when I go to ~/neuron/nrn/src/nrniv , running "./nrniv -python" works fine. I can also run "import hoc" and "import nrn" with no issues.

These are the contents of my ~/.profile file:

echo now executing ~/.profile
export PATH=$HOME/local/bin:$PATH
export PYTHONHOME=//anaconda/envs/neuronEnv
export PYTHONPATH=//anaconda/envs/neuronEnv/lib/python3.7/site-packages
export NRN_PYLIB=//anaconda/envs/neuronEnv/lib/libpython3.7m.dylib
export LB_LIBRARY_PATH=//anaconda/envs/neuronEnv/lib
source ~/neuron/nrnenv


The error occurs when I open Python independently, and run "import neuron" (here's the verbose output):

>>> import neuron
# //anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__pycache__/__init__.cpython-37.pyc matches //anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__init__.py
# code object from '//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__pycache__/__init__.cpython-37.pyc'
Traceback (most recent call last):
File "//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__init__.py", line 106, in <module>
import hoc
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'hoc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__init__.py", line 110, in <module>
import neuron.hoc
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
File "<frozen importlib._bootstrap>", line 583, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1043, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: dlopen(//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/hoc.cpython-37m-darwin.so, 2): Symbol not found: __ZN9ivSession8instanceEv
Referenced from: /nrn/x86_64/lib/libnrnpython3.0.dylib
Expected in: flat namespace
in /nrn/x86_64/lib/libnrnpython3.0.dylib

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/__init__.py", line 112, in <module>
exec("import neuron.hoc%d%d as hoc" % (sys.version_info[0], sys.version_info[1]))
File "<string>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'neuron.hoc37'

hines
Site Admin
Posts: 1595
Joined: Wed May 18, 2005 3:32 pm

Re: Installation Help: Fail to "import neuron" in Python

Post by hines » Wed Mar 25, 2020 12:41 pm

You didn't mention whether you installed from sources or a pkg file? I'll assume the former.
You didn't mention how you configured.
So I don't know where the neuron module was installed. Or where the bulk of neuron itself was installed.
With your PATH=$HOME/local/bin I assume you used cmake (configure would install nrniv in <prefix>/x86_64/bin)
but cmake would have it installed in that PATH if you used the cmake option -DCMAKE_INSTALL_PREFIX=$HOME/local .
I assume you requested the neuron module to be installed in //anaconda/envs/neuronEnv/lib/python3.7/site-packages ?
What option did you use so that would happen?

When you ran python3.7 and 'import neuron' I see you found the neuron module but the hoc module failed to load. There is often a good hint
about what is going wrong if one looks at
otool -L //anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/hoc.cpython-37m-darwin.so
ImportError: dlopen(//anaconda/envs/neuronEnv/lib/python3.7/site-packages/neuron/hoc.cpython-37m-darwin.so, 2): Symbol not found: __ZN9ivSession8instanceEv
Referenced from: /nrn/x86_64/lib/libnrnpython3.0.dylib
Well, it looks like many of my above assumptions are incorrect. Since you are looking in /nrn/x86_64/lib you must have configured with configure.
The --prefix is strange, though, as by default it would be /usr/local/nrn. If you used --prefix=/nrn then your PATH should have /nrn/x86_64/bin .
The actual 'Symbol not found' error refers to an InterViews name. So it seems that libnrnpython3.0.dylib did not get linked against InterViews.

Anyway, if you answer my questions above there may be a simple fix or things are still confusing to me we can try building from the latest
repository source with cmake.

byronprice
Posts: 3
Joined: Wed Mar 18, 2020 7:18 pm

Re: Installation Help: Fail to "import neuron" in Python

Post by byronprice » Wed Mar 25, 2020 1:13 pm

I will be honest: I'm a poor to bad programmer, so that likely explains most of the issues here. I was looking at some instructions on PyNN to get everything installed. I set up the Anaconda environment, pulled the package off of Github then configured with ../nrn/configure --prefix=$IDIR/nrn --with-nrnpython=dynamic --with-paranrn=dynamic ... where I've done export IDIR=/Applications/NEURON-7.6 . The Github repo is in ~/neuron . I've got NEURON-7.8 running, so I screwed that part up pretty good. However, the "nrniv -python" command still works from within ~/neuron/nrn/src/nrniv/ . Maybe I should just start from scratch.

hines
Site Admin
Posts: 1595
Joined: Wed May 18, 2005 3:32 pm

Re: Installation Help: Fail to "import neuron" in Python

Post by hines » Wed Mar 25, 2020 5:26 pm

I think the easiest installation is to try to remove all of what you have done and download
https://neuron.yale.edu/ftp/neuron/vers ... -37-38.pkg
and double click on it.
If that works and you then want to build from github sources, I can give the recipe for a cmake build.

byronprice
Posts: 3
Joined: Wed Mar 18, 2020 7:18 pm

Re: Installation Help: Fail to "import neuron" in Python

Post by byronprice » Thu Mar 26, 2020 11:18 am

Got it working. Thank you for your help. Note to self: never install from third-party instructions.

Post Reply