ModelView and ModuleNotFoundError: No module named 'numpy'

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

Moderator: hines

Post Reply
wlkath
Posts: 18
Joined: Wed Jun 08, 2005 12:39 am
Location: Northwestern University
Contact:

ModelView and ModuleNotFoundError: No module named 'numpy'

Post by wlkath »

OK, here's another question.

I have used mamba to set up a python environment for NEURON. If I activate this environment, start python, and import neuron all seems OK.

If, however, I start nrngui and load an old (pre-python) NEURON model and start a ModelView, I get this error:

oc>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Applications/NEURON/lib/python/neuron/rxd/__init__.py", line 7, in <module>
from . import rxd, constants
File "/Applications/NEURON/lib/python/neuron/rxd/rxd.py", line 2, in <module>
from . import species, node, section1d, region, generalizedReaction, constants
File "/Applications/NEURON/lib/python/neuron/rxd/species.py", line 1, in <module>
from .rxdmath import _Arithmeticed
File "/Applications/NEURON/lib/python/neuron/rxd/rxdmath.py", line 2, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'

I'm not doing anything with python; why am I getting a python error?

Also, I *do* have numpy installed in this environment, but I'm guessing NEURON is not finding it (maybe it's looking in the base python environment, where nothing is installed?).

I tried setting PYTHONPATH, but either I'm not pointing to the correct location or it's the wrong environment variable.

The larger question: what is the right way to get NEURON to interact properly with a python environment?

Thanks!
wlkath
Posts: 18
Joined: Wed Jun 08, 2005 12:39 am
Location: Northwestern University
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by wlkath »

Well, I think I answered some of my question. This site https://docs.conda.io/projects/conda/en ... ation.html explains about per-environment activation and deactivation scripts. I have implemented that and have tried adding additional paths to PYTHONPATH when activating this environment, including the full path to numpy, but it's still being ignored.
wlkath
Posts: 18
Joined: Wed Jun 08, 2005 12:39 am
Location: Northwestern University
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by wlkath »

Maybe I'm being dense. I was starting NEURON from the command line:

Code: Select all

$ nrngui file.hoc
If I run

Code: Select all

$ python
>>> from neuron import h,gui
and then load file.hoc from the gui, I don't get the error.

Was it incorrect of me to try to start NEURON from the command line?
wlkath
Posts: 18
Joined: Wed Jun 08, 2005 12:39 am
Location: Northwestern University
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by wlkath »

OK, I found the right documentation page.

Setting NRN_PYTHONEXE in the shell script that gets called when activating the python environment used for NEURON resolves the problem.

Apologies for all the posts.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by ted »

Actually no apologies are necessary. You ran into an instance of something that should never happen: a booby trap dependency, and worse, it looks like a gratuitous dependency (one that shouldn't exist in the first place because it is unnecessary). IMO all valid dependencies should either
resolve automatically
or
generate an informative error message
or (and this is only marginally acceptable)
be documented clearly and in as salient a manner as possible so users don't have to hunt around for answers.

Thanks for your posts in this thread--maybe they'll help someone else who runs into this particular issue.

BTW what OS are you using?
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by ramcdougal »

A follow up question: how did you install NEURON?

From the paths, it looks like you ran in macOS. Doing a "pip install neuron" is supposed to handle all the dependencies, including numpy. (This works for linux and macOS, but unfortunately we don't support pip on Windows.)

I believe the underlying issue, which I'd call a bug or at least under-design on the NEURON side is that when ModelView checks to see if there are reaction-diffusion dynamics to report, it tries to load the reaction-diffusion module which does require numpy.

I created a GitHub issue to address this: https://github.com/neuronsimulator/nrn/issues/2367
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by ted »

Thanks. As you so concisely stated in that issue
numpy should not be required for users only using HOC with no reaction-diffusion.
wlkath
Posts: 18
Joined: Wed Jun 08, 2005 12:39 am
Location: Northwestern University
Contact:

Re: ModelView and ModuleNotFoundError: No module named 'numpy'

Post by wlkath »

To follow up on the questions:

I have a M1 Mac running Monterey (12.6.5 at the time)

I installed NEURON using the dmg installer. Next time I'll use pip. I've had trouble with python environments in which I used pip to install things, so I've been trying to stick with using mamba to install python packages.
Post Reply