Neuron as Python Module for Windows

Post Reply
uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Neuron as Python Module for Windows

Post by uri.cohen »

There seems to be many people trying to build NEURON from sources just to get it to work as a python module (see http://www.neuron.yale.edu/phpBB/viewto ... f=5&t=2081 http://www.neuron.yale.edu/phpBB/viewto ... f=5&t=1507 http://www.neuron.yale.edu/phpBB/viewto ... f=5&t=1809 and http://www.neuron.yale.edu/phpBB/viewto ... 970&p=7256 ).

Also I have found a comment by ted (here: http://www.neuron.yale.edu/phpBB/viewto ... 218&p=8509) that
MSWin users get a bit of a free ride--Python is compiled into the NEURON installer
So my questions:
1) Does the current NEURON for windows binary includes python? Is it possible to install a NEURON as python module on windows without compiling from sources?
2) With the growing popularity of PyNN and neuronvisio, which both require a version of NEURON which can be a Python Module, are there any plans to release an official such version for all platforms?
hines
Site Admin
Posts: 1603
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python Module for Windows

Post by hines »

1) Yes but it is a cygwin version of Python. An example of a pure mswin version of
python is the enthought distribution and I have not been creating a NEURON setup.exe
built against that since NEURON's standard gui requires InterViews which presently
only works under cygwin.

2) If there is any demand for it, I suppose it would make sense to create a setup.exe that would
install as an extension to the enthought distribution. I've been having a great deal of trouble
with the slowness of building under cygwin in a VirtualBox and I've been wondering if the 'building
against enthought' task would be best carried out in a MinGW environment.
jgarrido
Posts: 2
Joined: Sun Jul 24, 2011 12:11 pm

Re: Neuron as Python Module for Windows

Post by jgarrido »

Hello everybody,

I have been unsuccessfully setting Neuron as Python module for some days in my Windows 7. Previously I had installed Neuron + Python in Ubuntu with no problem at all.

The steps that I have followed after reading a lot of posts and links on this forum are the next ones:
1. Install Cygwin
2. Download NEURON and INTERVIEWS from http://www.neuron.yale.edu/ftp/neuron/versions/alpha/. Concretely I chose iv-17.tar.gz and nrn-7.2.alpha-524.tar.gz.
3. Extract the two packages in $HOME/neuron/iv and $HOME/neuron/nrn respectively.
4. Compile iv by means of:

Code: Select all

cd $HOME/neuron/iv
./configure --prefix=`pwd`
make
make install
and everything was ok.
4. Compile nrn by means of:

Code: Select all

cd $HOME/neuron/nrn
./configure --prefix=`pwd` --with-iv=$HOME/neuron/iv --with-nrnpython=/bin/python
make
make mswin
and it only returned and error as expected in the last mswin stage (nrnsetup.nsi). In fact, the main files (hocmodule.dll, cygIVhines-3.dll, and nrniv.dll) were at /cygdrive/c/marshalnrn/nrn/.

Then, I copied hocmodule.dll to hoc.pyd and set both $NEURONHOME and $PYTHONPATH by using:

Code: Select all

export NEURONHOME=/cygdrive/c/marshalnrn/nrn
export PYTHONPATH=/cygdrive/c/marshalnrn/nrn/bin:/cygdrive/c/marshalnrn/nrn/lib/python.
But afterwards, when I tried to load the neuron modules from the Python interpreter

Code: Select all

from neuron import h
I get the following Error:

Code: Select all

CODE: SELECT ALL
File "/cygdrive/c/marshalnrn/nrn/lib/python/neuron/__init__.py", line 81, in 
<module> import neuron.hoc
ImportError: No module named hoc
This mistake has already been commented on http://www.neuron.yale.edu/phpbb/viewto ... f=5&t=2032 but I can not find the key point to solve it. It looks that Python can not find the hoc.pyd module in the path, but it should do it.

Does anyone have any suggestion? I am getting crazy with this mistake and I am seriously considering installing some Linux dist on this PC as well.

Many thanks in advance
hines
Site Admin
Posts: 1603
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python Module for Windows

Post by hines »

Try copying the hoc.pyd file to /bin/python . I hope you have been launching /bin/python from an
rxvt cygwin terminal as the major theme here has been that one cannot extend the mswin
enthought version of python with a cygwin version of NEURON.
If you continue to have trouble with this, tell me the version of Python you launch and I'll
try it on my mswin virtualbox and determine the proper name for hocmodule.dll along with
its proper location.
jgarrido
Posts: 2
Joined: Sun Jul 24, 2011 12:11 pm

Re: Neuron as Python Module for Windows

Post by jgarrido »

Thank you Michael for your prompt response :)
Try copying the hoc.pyd file to /bin/python
I could not do it since /bin/python is the python interpreter executable and not a folder. But after reading your comment I have just achieved to load the neuron module from python interpreter. I got it by being located at the neuron bin folder (/cygdrive/c/marshalnrn/nrn/bin). In this case, the import command works fine. Therefore, it seems to be a problem with the Python path, because even when /cygdrive/c/marshalnrn/nrn/bin is in the $PYTHONPATH, the hoc.pyd can not be loaded. Here you have the value of the sys.path variable:

Code: Select all

['', '', '/cygdrive/c/marshalnrn/nrn/bin', '/cygdrive/c/marshalnrn/nrn/lib/python', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-cygwin', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages', '/c/marshalnrn/nrn/lib/python']
 
My Python version is Python 2.6.5 (r265:79063). This is the default version which Cygwin installed just yesterday.

After loading the neuron module from Python, I have tried to show the Neuron GUI by means of:

Code: Select all

from neuron import gui
The GUI is shown, but it seems to be frozen. I guess this is related to the (non-extended) Python version. Am I right? And in this case, is there any way to run the GUI from Python in mswin systems?

Thank you again for your support
hines
Site Admin
Posts: 1603
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as Python Module for Windows

Post by hines »

Ok. I just built a cywin version of NEURON against cywin python 2.6.5 ending with
make mswin
so that everything is in /cygdrive/c/marshalnrn/nrn
After a good deal of experimentation,
I see that for this python one does not change the name of hocmodule.dll to hoc.pyd
but leaves it as is and modifies environment variables so that
export NEURONHOME=/cygdrive/c/marshalnrn/nrn
export PATH=$PATH:$NEURONHOME/bin
export PYTHONPATH=$NEURONHOME/lib/python:$NEURONHOME/bin

Odd that one needs the bin directory in both PATH and PYTHONPATH.

I need to look further into why 'from neuron import gui' is failing.
uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Re: Neuron as Python Module for Windows

Post by uri.cohen »

Thanks for your rapid and clear reply.
I would like to compile the code so that it will work with a pure mswin version of Python (I used ActivePython 2.7). No GUI is required, as I just want to use NEURON as a module through PyNN. I Followed the instructions in this forum with the latest code (cygwin + nrn) and it fails for me during 'configure' with the following message, which other have reported as well (but didn't specified the cause for some reason):

Code: Select all

configure:16600: Because this python is not a CYGWIN program, build as a MinGW program as though
 --disable-cygwin --with-readline=no --without-iv --without-memacs was invoked.
That is, build a version suitable mostly as a Python extension.
configure:16607: checking nrnpython configuration
configure:16818: checking if python include files and libraries work
configure:16844: gcc -o conftest.exe -mno-cygwin -g -O2 -I/cygdrive/c/Python27/include   conftest.c -L/cygdrive/c/Python27/libs -lpython27   >&5
gcc: The -mno-cygwin flag has been removed; use a mingw-targeted cross-compiler.
... (additional lines omitted) ...
configure:16851: error: could not run a test that used the python library.
Examine config.log to see error details. Something wrong with
	PYLIB=-L/cygdrive/c/Python27/libs -lpython27
or
	PYLIBDIR=/cygdrive/c/Python27/libs
or
	PYLIBLINK=-L/cygdrive/c/Python27/libs -lpython27
or
	PYINCDIR=/cygdrive/c/Python27/include
What am I missing?
- Is indeed the 'mno-cygwin' flag no longer supported in cygwin? (I found the ~10 usages of it in the trunk code)
- Are there MinGW-specific instructions to build neuron as python module?
- How come the enthought distribution work, anyway? The failure I experience would have happen with enthought too, I guess.
If there is any demand for it, I suppose it would make sense to create a setup.exe that would
install as an extension to the enthought distribution. I've been having a great deal of trouble
with the slowness of building under cygwin in a VirtualBox and I've been wondering if the 'building
against enthought' task would be best carried out in a MinGW environment.
It has my support...

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

Re: Neuron as Python Module for Windows

Post by hines »

I believe that in the past we have been building with a gcc 3 compiler
and the necessary option was removed in gcc 4. Check to see if you have
gcc 3 and, if so, use that as the compiler (use CC=... and CXX=... on the
configure line). I will need to experiment with a mingw installation to see how
to compile with that environment in the future.
uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Re: Neuron as Python Module for Windows

Post by uri.cohen »

Your tip was great, and I found 3-4 additional steps were needed to make NEURON work as a module with my native-Windows ActiveState python 2.7.
See the preview below :)
I'll share my results soon, as I had to make some minor changes to the code which I'd like to contribute first.

Code: Select all

C:\marshalnrn\nrn\bin>python
ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb  7 2011, 11:30:38) [MSC v.1500 32 bit (Intel)] on win32
>>> from neuron import h
NEURON -- VERSION 7.2 (527+:a38b8d137de6+) 2011-07-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html

>>> h.neuronhome()
'c:/marshalnrn/nrn'
>>> h.load_file('stdrun.hoc')
1.0
blloyd
Posts: 11
Joined: Tue Aug 16, 2011 4:33 am

Re: Neuron as Python Module for Windows

Post by blloyd »

Hi,

It seems you have managed to get it to compile and run. Could you please share the steps necessary to do it?

I have tried to follow the (many different) posts to manage to compile NEURON for Windows, without GUI, for a native Enthought python (2.7.1).
However, the configure step fails when trying to compile a test program, which uses Python.

The config.log says these symbols are missing (undefined reference to `__imp__Py_Initialize', undefined reference to `__imp__Py_Finalize').
I tried to use 'nm' to see if the symbols existed in python27.lib, but could not any sensible results.

I can post my full configure/build script for more details.

Thanks!
blloyd
Posts: 11
Joined: Tue Aug 16, 2011 4:33 am

Re: Neuron as Python Module for Windows

Post by blloyd »

I should have added:
I am trying in Windows 7, 64-bit.
The Cygwin version is a recent one (cygwin_nt-6.1-WOW64).
The gcc compiler is: gcc-3.4.4
Post Reply