Neuron as Python module in Win (again)

tk_ac
Posts: 6
Joined: Wed Aug 22, 2007 11:26 am
Location: RWTH Aachen

Neuron as Python module in Win (again)

Post by tk_ac »

Can I humbly inquire what the general consensus is about running NEURON as Python module under Windows 7? I use Python (xy) and was able to install pyNeuron (with pip), but somehow I can never load any additional mechanisms from nrnmech.dll. There are many confusing posts about this topic in general -- it seems impossible to compile mod files under Windows to use in a non-Cygwin Python -- true or not?
Any coherent update from anyone successfully using pyNeuron would be greatly appreciated!
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

At http://www.neuron.yale.edu/ftp/neuron/versions/alpha/ the files
nrn-7.3.alpha-597-setup-i686.exe
and
nrn-7.3.alpha-599-setup-x86_64.exe
build non-cygwin nrnmech.dll files for mswin. They are importable with enthought python and InterViews is working properly. The setup.exe files come with enough MinGW to buld the nrnmech.dll from mod files via the mknrndll icon. By setting NEURONHOME and PYTHONPATH (I forget if a setting for PATH is also necessary) one can launch python and import neuron.

But there is one serious problem with both the i686 and x86_64, and a bug for some models for the x86_64 version. The first is that there seems to be an inconsistency between the MinGW I built NEURON with and distribute and the MinGW used by enthought python (or at least used when numpy was built). They use different versions of some internal microsoft system dll that cannot both be in memory at the same time. My intention is to see if i can build NEURON using only the MinGW compiler and libraries distributed with enthought python. If this is the case, I will no longer distribute MinGW with the neuron setup.exe.

The bottom line is that it will take me a few weeks to resolve all these issues. However when that happens it will be possible for a PyNeuron to be create which is complete and easily installable. Until then, the only option for 64bit mswin is to use a 64 bit linux virtualbox guest.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

The serious problem I mentioned above is present only when one launches nrniv. No problem with 'import numpy' if one launches python and
from neuron import h
import numpy

Note that when launching python, 'import neuron' requires
export NEURONHOME=/c/where/nrn/is/installed
export PYTHONPATH=/c/where/nrn/is/installed/lib/python
and in /c/where/nrn/is/installed/bin (or bin64) rename hocmodule.dll to hoc.pyd
You also probably need the previous folder in your PATH.
tk_ac
Posts: 6
Joined: Wed Aug 22, 2007 11:26 am
Location: RWTH Aachen

Re: Neuron as Python module in Win (again)

Post by tk_ac »

Michael, thanks for your update on the situation! Looks like a good plan is to sit tight and wait a few weeks (regarding Neuron as a module in native Python on Win7-64). At the same time I can slowly work on converting my MATLAB/Neuron mix to Python on my Linux Box.
tk_ac
Posts: 6
Joined: Wed Aug 22, 2007 11:26 am
Location: RWTH Aachen

Re: Neuron as Python module in Win (again)

Post by tk_ac »

not really related, just that you know: I installed the "nrn-7.3.alpha-597-setup-i686.exe" on a 32bit machine (this is Win Vista), and here mknrndll does not build anything:

Code: Select all

mod_func.c:1:19: fatal error: stdio.h: no such file or directory
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

Ok. I believe it should work now. Try
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
It is a bit bloated compared the the x86_64-w64-mingw32 version since 29MB of it is mingw for mknrndll.
I need to prune away the unneeded parts and work on some details like double clicking on hoc files.
tk_ac
Posts: 6
Joined: Wed Aug 22, 2007 11:26 am
Location: RWTH Aachen

Re: Neuron as Python module in Win (again)

Post by tk_ac »

Good news! I can now compile nmodl mechanisms that work with pyNeuron, when I use the mknrndll from this package: "nrn-7.3.alpha-694.i686-pc-mingw32-setup.exe". This is on a Win7-64bit machine with Python(x,y) (32bit) and pyNeuron installed via PIP.
So I think we can consider this thread "solved". Thanks a lot!
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

Thanks. I'm glad to get verification that the installer works on a machine other than my own.
There is also a corresponding 64 bit version that, I believe, works well on 64 bit processors (if you need
arrays larger that 4GB bytes in size). It's only problem (that I am aware of) is that the Shape and Graph
printfile methods generate an error.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: Neuron as Python module in Win (again)

Post by patoorio »

Hi,

I could make it work under Win 8 x64, with the latest Python x,y. However there are two issues:
1) The Neuron version installed by pip is 7.2, not (yet?) 7.3. I really need 7.3 because I'm making use of the as_numpy() function. Will it be updated anytime? Is there anything I can do to help?
2) GUI doesn't start. I make

Code: Select all

from neuron import gui
and nothing happens. Well, the module is apparently imported because no error code is generated, but no graphic items are displayed (no menu, no graph, etc). Is this expected?

Can I solve these issues by compiling from source?

Thanks!
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

Sadly, I have not yet been able to get all the pieces (enthought, InterViews, NEURON, MPI, 64bit mingw) working in all combinations.
In particular, if one uses python as the console interpreter, one cannot use InterViews graphics. Some months ago I was getting sucked
deeply into microsoft world trying to understand things like manifest files. I'd probably get inspired again if someone could successfully build openmpi under mingw64.
(I was successful with mich2 but it seems that enthought's scipy, mayavi, ... require openmpi.)

I'm afraid I don't know anything about pip.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: Neuron as Python module in Win (again)

Post by patoorio »

Oh, I can see... and I fully understand!
But this is about the GUI, right?
What about version 7.3? Is there anything I can do about it? (compile, etc.?)
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

you can extend Python xy with NEURON (but not use any interviews gui) if you install
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
and then set the environment variables mentioned in the 16May2012 12:21 post above.

Trying to build from sources is possible if you follow the instructions in
http://www.neuron.yale.edu/hg/neuron/nr ... howtomingw
what makes it most painful is the time it takes to install a full cygwin and mingw development environment.
Hopefully this summer I will fill in most of the holes. But my biggest problem is to get an openmpi installation for mingw64.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: Neuron as Python module in Win (again)

Post by patoorio »

hines wrote:you can extend Python xy with NEURON (but not use any interviews gui) if you install
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
and then set the environment variables mentioned in the 16May2012 12:21 post above.
Well, I took some time before trying (actually I installed Linux in my new laptop but not everything worked fine so I went back to Windows)
The thing is I'm getting the 'No module named hoc' error. I tried with both 32bit- and 64bit-Neuron. Anything else that I should do besides renaming hocmodule and setting NEURONHOME, PYTHONHOME and the path environment?
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python module in Win (again)

Post by hines »

That should be sufficient. The only thing I'm never certain about is the name of hocmodule.dll. If hoc.pyd does not do the trick, you might try hoc.dll .
In different situations each of the three has been needed in the past. Another experiment is to launch in the folder where the hoc.dll exists but I would have thought PATH would
take care of that issue.
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: Neuron as Python module in Win (again)

Post by patoorio »

Well, I'm still not getting it.
With Neuron 7.3 x64, I get the 'no module named hoc' error, unless I add c:\nrn73x64\bin64 to PYTHONPATH as well. It also works to copy hoc.pyd to the c:\nrn73x64\lib\python\neuron folder. In either case, however I get the following error: 'DLL load error: hoc.pyd is not a valid win32 application' (or something like that; I don't remember exactly).
So I switched to 32-bit neuron. Again I have to add c:\nrn73\bin to PYTHONPATH otherwise I have the 'no module named hoc' error. In this case, I have the following error when trying to import: 'DLL load failed: cannot find specified module' (maybe those are not the exact words; I'm translating from spanish)
I have taken special care of changing all the environment variables when switching from 32bit to 64bit and back. What else can be wrong? What is the module it cannot find?

By the way, the full error is:

Code: Select all

----> 1 from neuron import h

C:\nrn73\lib\python\neuron\__init__.py in <module>()
    104 except:
    105   #Python3.1 extending needs to look into the module explicitly
--> 106   import neuron.hoc
    107
    108 import nrn

ImportError: DLL load failed: No se puede encontrar el m¾dulo especificado.
So it seems that 'try: import hoc' (line 102 of __init__.py) is failing. Well, that's kind of obvious.
Thank you for your help!
Post Reply