Neuron as a Python Module Redux

Post Reply
Bill Connelly
Posts: 86
Joined: Thu May 22, 2008 11:54 pm
Location: Australian National University

Neuron as a Python Module Redux

Post by Bill Connelly »

So it's getting around to 4 years since the last thread on this was started, so I feel another one is in order. I've read through the other threads but the advice does not really make sense to me, or does it work when it does.

Specifics:
I'm running Windows 8.1 on a 64 bit machine,
I'm running 64 Bit Python 2.7.9 (just normal python. Not enthought or anything else)
I've freshly installed Neuron 7.4 64bit.

When I run the nrniv_python shortcut, everything appears to work. However, if I open Python in any other way I run into problems

Code: Select all

Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from neuron import h

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from neuron import h
  File "c:\nrn\lib\python\neuron\__init__.py", line 106, in <module>
    import neuron.hoc
ImportError: DLL load failed: The specified module could not be found.
Is there any way to get around this?

p.s. If the advice to fix this involves typing to the command line, can you please be explicit about which command line? Python, Windows, Neuron...

Thanks.
ramcdougal
Posts: 269
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Neuron as a Python Module Redux

Post by ramcdougal »

Open a DOS prompt (cmd) and try running:

Code: Select all

set PATH=c:\nrn\bin;%PATH%
Then (in the same window), type "python" and "import neuron". Does that work?

If so, you can make the change permanent by adding c:\nrn\bin to the PATH environment variable; instructions are available here and elsewhere.

A similar problem can occur on the mac. On that platform, the nrnpyenv.sh script can be used to guess PATH, PYTHONPATH, and PYTHONHOME envrionment variables.
Bill Connelly
Posts: 86
Joined: Thu May 22, 2008 11:54 pm
Location: Australian National University

Re: Neuron as a Python Module Redux

Post by Bill Connelly »

You're a legend. I thought I had that bit all sorted out because the NEURONHOME and PYTHONPATH were all set already. But yes, still needed to add something to path. Excellent, thank you very much, I am in your debt.
SurG
Posts: 11
Joined: Fri Jun 19, 2015 4:39 pm

Re: Neuron as a Python Module Redux

Post by SurG »

We are running Neuron 7.4 and Python 2.7.11 in Windows 7 ( 64 bit). We were also facing the exact same problem and we implemented the solutions suggested. However, we are still unable to import Neuron on the Python terminal. Please advice as to what we can do next.

Deactivating environment "C:\Users\Panther\Anaconda2"...
Activating environment "C:\Users\Panther\Anaconda2"...

[Anaconda2] C:\Users\Panther>python
Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Jan 29 2016, 15:36:56) [MSC v.1500 32 bit (Intel)] on win32
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://anaconda.org

>>> from neuron import h
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\nrn\lib\python\neuron\__init__.py", line 106, in <module>
import neuron.hoc
ImportError: No module named hoc
>>>
ramcdougal
Posts: 269
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Neuron as a Python Module Redux

Post by ramcdougal »

Try permanently setting the PATH environment variable for the system instead of through the command line. (See below.) In addition, make sure you are using the 32 bit NEURON to match your 32 bit Python.

For completeness, I just tried the following on a machine starting from no OS, and it worked:
  • Installed Windows 7 SP 1
  • Installed 32 bit* Anaconda 2.5.0 for all users otherwise accepting the defaults
  • Installed 32 bit NEURON 7.4 as downloaded today, March 11th, selecting the bold option to "Set DOS environment" ** but otherwise accepting the defaults
  • "start button" - right-click on "computer" - properties - "Advanced system settings" - "Environment Variables" - "New" ***
  • For "Variable name": PATH
  • For "Variable value": c:\nrn\bin
  • Then click "OK"
  • Then click "OK" on the dialog below that
  • Then click "OK" on the third dialog below that
  • Launch the Anaconda Prompt****, *****
  • Type: python
  • Type: import neuron
Success:

Code: Select all

Deactivating environment "C:\Anaconda2"...
Activating environment "C:\Anaconda2"...

[Anaconda 2] C:\Users\ramcdougal>python
Python 2.7.11 |Anaconda 2.5.0 (32-bit)| (default, Jan 29 2016, 15:36:56) [MSC v.
1500 32 bit (Intel)] on win32
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://anaconda.org
>>> import neuron
NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

>>>

* I note that you're using 32 bit Python on 64-bit Windows 7, so these instructions follow that and use 32 bit NEURON as well. I assume 64 bit NEURON will not play nice with 32 bit Python, but I did not test that.

** The "Set DOS environment" option sets the NEURONHOME environment variable to "c:\nrn" and adds "c:\nrn\lib\python" to the PYTHONPATH

*** If you already have a PATH environment variable, edit it instead and add c:\nrn\bin

**** In particular, the changes we just made will only work with NEW console windows; do not reuse an existing one, just launch a new one

***** at this point, I also tested: cmd, ipython, and Jupyter QtConsole (for the last two, Python is already launched so skip that step). Each worked
SurG
Posts: 11
Joined: Fri Jun 19, 2015 4:39 pm

Re: Neuron as a Python Module Redux

Post by SurG »

Thank you very much sir. This worked!
basjanzandt

Re: Neuron as a Python Module Redux

Post by basjanzandt »

Thanks a lot. This solution worked for us as well on Windows 10, using 64 bit anaconda and 64 bit NEURON 7.4.
aaronmil
Posts: 35
Joined: Fri Apr 25, 2014 10:54 am

Re: Neuron as a Python Module Redux

Post by aaronmil »

Hi Rob,

I'm having an awful time with a strange issue on my colleague's Windows 10 machine. We have 64-bit Anaconda2, and 64-bit NEURON 7.4 from the standard windows installer. We can run ipython, import neuron, and run simulations just fine - but only if we use the "ball and stick" specification of section morphologies. If we try to execute code that uses the n3d() method of a h.Section object, it returns that 'n3d is not an attribute of Section'. We have uninstalled and reinstalled Anaconda and NEURON a few ways now, and just cannot get it to work. Any ideas? Thank you.

Aaron
ramcdougal wrote:Try permanently setting the PATH environment variable for the system instead of through the command line. (See below.) In addition, make sure you are using the 32 bit NEURON to match your 32 bit Python.

For completeness, I just tried the following on a machine starting from no OS, and it worked:
  • Installed Windows 7 SP 1
  • Installed 32 bit* Anaconda 2.5.0 for all users otherwise accepting the defaults
  • Installed 32 bit NEURON 7.4 as downloaded today, March 11th, selecting the bold option to "Set DOS environment" ** but otherwise accepting the defaults
  • "start button" - right-click on "computer" - properties - "Advanced system settings" - "Environment Variables" - "New" ***
  • For "Variable name": PATH
  • For "Variable value": c:\nrn\bin
  • Then click "OK"
  • Then click "OK" on the dialog below that
  • Then click "OK" on the third dialog below that
  • Launch the Anaconda Prompt****, *****
  • Type: python
  • Type: import neuron
Last edited by aaronmil on Tue Feb 07, 2017 1:54 am, edited 1 time in total.
ted
Site Admin
Posts: 6358
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Neuron as a Python Module Redux

Post by ted »

aaronmil, unless you're addressing a specific item from ramcdougal's post, there's really no need to quote any of his message, let alone the entire post. If everybody did that, the Forum would be much larger and much harder to wade through than it already is.
Post Reply