Neuron as python module in windows 7

selfdestructo
Posts: 32
Joined: Wed Oct 14, 2009 11:12 am

Neuron as python module in windows 7

Post by selfdestructo »

Hi!

First, I am on Windows 7 32bit, Python 2.6.3, Cygwin 1.7 beta, and trying to use the Neuron 7- and iv 1.7 source code packages.

I have a problem building Neuron as a python module on this config, as described in another post here; http://www.neuron.yale.edu/phpBB/viewto ... 07&start=0, modified with current version numbers.

Does anybody have a clue of what can be done different? I don't know how to invoke a "mingw-targeted cross-compiler", which appear to be the issue.

Here is the sh-script describing exactly what I've tried.

Code: Select all

#!/bin/sh

#cd $HOME
mv neuron neuron_old
mkdir neuron
cp iv-17.tar.gz neuron
cp nrn-7.0.tar.gz neuron
cd neuron
tar xzf iv-17.tar.gz
tar xzf nrn-7.0.tar.gz
# renaming the new directories iv and nrn makes life simpler later on
mv iv-17 iv
mv nrn-7.0 nrn

#compiling iv
cd iv
./configure --prefix=`pwd`
make
make install

#compiling neuron
cd ..
cd nrn
#./configure --prefix=`pwd`
#make
## unlike the UNIX installation, we DO NOT do make install

./configure --prefix=`pwd` --with-nrnpython
make
./configure --prefix=`pwd` --with-nrnpython \
    --without-iv --without-memacs --with-readline=no --without-nmodl
    CFLAGS="-mno-cygwin" CXXFLAGS="-mno-cygwin" \
    PYLIBDIR=/cygdrive/c/Python26/libs \
    PYINCDIR=/cygdrive/c/Python26/Include \
    PYLIBLINK="-L/cygdrive/c/Python26/libs -lpython26" \
    PYLIB="-L/cygdrive/c/Python26/libs -lpython26" \

make
cd src/mswin
cp hocmodule.dll c:/Python26/hoc.dll

exit 0
The final 'make' fails, no hocmodule.dll is created;

Code: Select all

...
g++: The -mno-cygwin flag has been removed; use a mingw-targeted cross-compiler.

make[3]: *** [neuron.exe] Error 1
make[3]: Leaving directory `/home/neuron/nrn/src/nrniv´
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/neuron/nrn/src´
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/neuron/nrn´
make: *** [all] Error 2
cp: cannot stat `hocmodule.dll´: No such file or directory

EH@Espen-PC /Home
$
Here are the Ipython output from an example python-script, which ask for the module "neuron", if it helps;

Code: Select all

In [6]: execfile("ex1.py")
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)

c:\Users\EH\Python\LFPy\examples\<ipython console> in <module>()

c:\Users\EH\Python\LFPy\examples\ex1.py in <module>()
      2 import numpy
----> 3 import LFPy
      4
      5 ioff()
      6 close('all')

C:\Python26\lib\site-packages\LFPy\__init__.py in <module>()
      2
----> 3 from cell import Cell
      4 from synapse import Synapse
      5 from lfpnm import LFPNM
      6 import tools

C:\Python26\lib\site-packages\LFPy\cell.py in <module>()
      2 import numpy
      3 import copy
      4 import cPickle
      5 import pylab #comment out if running on Stallo
      6 import os

ImportError: No module named neuron

In [7]:
hines
Site Admin
Posts: 1601
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as python module in windows 7

Post by hines »

I can give a few suggestions but I don't have a Windows 7 installation available to try a build myself so they may not be sufficient.

No need to build InterViews since you are using the --without-iv for NEURON.

The topic you mentioned recommended --disable-cygwin

You are using a python from /cygdrive/c/Python26 and this seems likely to be a cygwin version, not a windows version of python.

You should start from the alpha sources at
http://www.neuron.yale.edu/ftp/neuron/versions/alpha/

I have a very recent cygwin on my xp machine and will see if I can build the mingw version.
hines
Site Admin
Posts: 1601
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as python module in windows 7

Post by hines »

The topic you mentioned recommended --disable-cygwin
Turns out this is unnecessary. When Python is a windows program,
Configure will automatically add
--disable-cygwin --with-readline=no --without-iv --without-memacs
You are using a python from /cygdrive/c/Python26
I wasn't very observant. This is a windows version.

I just built a mingw version using the latest hg repository sources.
There was a bug in nrn/src/mswin/nrncygso.sh.in which you can fix by
adding three characters around the inithoc.o indicated in
http://www.neuron.yale.edu/hg/neuron/nr ... 1260a01792

mkdir nrnwinpy
cd nrnwinpy
../nrn/configure --prefix=`pwd` --with-nrnpython=/cygdrive/c/Python25/python
make
make mswin

I then tested in Command Prompt window with
cd c:\marshalnrn\nrn\bin
mv hocmodule.dll hoc.pyd
set PYTHONPATH=c:/marshalnrn/nrn/lib/python
set NEURONHOME=c:/marshalnrn/nrn
c:\Python25\python
from neuron import h
h.neuronhome() # returns c:/marshalnrn/nrn
h.load_file('stdrun.hoc') #returns 1

If you launch from somewhere else then you need to put hoc.pyd and nrniv.dll where they will be found.
selfdestructo
Posts: 32
Joined: Wed Oct 14, 2009 11:12 am

Re: Neuron as python module in windows 7

Post by selfdestructo »

Thanks for looking into it, but your suggested method give me some new problem with the configure-script unfortunately.
Running configure as below with your suggested flags, from latest hg sources and the corrected nrncygso.sh.in;
...
../neuron/nrn/configure --prefix=`pwd` --with-nrnpython=/cygdrive/c/Python26/python
will not complete configure correctly, ending with;
could not run a test that used the python library.
Examine config.log to see error details. Something wrong with
PYLIB=-L/cygdrive/c/Python26/libs -lpython26
or
PYLIBDIR=/cygdrive/c/Python26/libs
or
PYLIBLINK=-L/cygdrive/c/Python26/libs -lpython26
or
PYINCDIR=/cygdrive/c/Python26/include
which looks correct to me.

I don't think I will spend much more time on this, I'm getting a Mac next week anyway. But if anyone have some suggestions, I will gladly it another try.

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

Re: Neuron as python module in windows 7

Post by hines »

One difference appears to be that I used the Enthought Python distribution
epd-5.1.1-win32-x86.msi from download.enthought.com
which installs Python25. When I get a chance I'll install Python26 and
see if I can reproduce the problem. If not, perhaps the issue is a difference between
windows 7 and xp
hines
Site Admin
Posts: 1601
Joined: Wed May 18, 2005 3:32 pm

Re: Neuron as python module in windows 7

Post by hines »

I installed the windows version of python-2.6.3 and don't see a problem with configure.
You might look at your config.log file to see precisely why it failed.
selfdestructo
Posts: 32
Joined: Wed Oct 14, 2009 11:12 am

Re: Neuron as python module in windows 7

Post by selfdestructo »

hines wrote:I installed the windows version of python-2.6.3 and don't see a problem with configure.
You might look at your config.log file to see precisely why it failed.
Yes, I did, didn't get any wiser, and concluded that my Cygwin-installation was to blame :) Thank you for your help!
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Re: Neuron as python module in windows 7

Post by Keivan »

Could you share your win 7 experience with us. I want to know is there any performance improvement (running a neuron model) compared to win XP using win 7? win 7 32 bit or 64 bit?
selfdestructo
Posts: 32
Joined: Wed Oct 14, 2009 11:12 am

Re: Neuron as python module in windows 7

Post by selfdestructo »

Keivan wrote:Could you share your win 7 experience with us. I want to know is there any performance improvement (running a neuron model) compared to win XP using win 7? win 7 32 bit or 64 bit?
Can´t say much about NEURON performance in 7 vs XP in 32b vs 64b mode, as I´ve only used the OS´s on my old Dell Inspiron 9300 with 1.7GHz Centrino and 2GB RAM, and have not done serious simulations on neither. The precompiled windows installation of NEURON 7.0 seems to work just fine.

But as far as Windows 7 itself is concerned, it is a pretty nice experience. It looks nice, is pretty snappy in terms of performance, appear to be very stable, I haven´t had problems getting programs to run (except neuron as python module :) ) not as annoying as Vista, I like how personal files and folder can be put into libraries, it works just fine in other words.
ted
Site Admin
Posts: 5793
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Neuron as python module in windows 7

Post by ted »

Just this last week an article appeared in InfoWorld that compared performance of XP, Vista and 7. Its principal focus was on tasks that involved multithreaded execution. Vista and 7 were both faster than XP, but pretty similar to each other i.e. Vista did better than 7 on some tasks, and vice versa.
Keivan
Posts: 127
Joined: Sat Apr 22, 2006 4:28 am

Re: Neuron as python module in windows 7

Post by Keivan »

Then, I should buy win 7 if neuron runs faster on it. I think win 7 32 bit should be the choice for neuron; because cygwin does not have a 64 bit version yet.
ted
Site Admin
Posts: 5793
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Neuron as python module in windows 7

Post by ted »

Keivan wrote:Then, I should buy win 7 if neuron runs faster on it.
Save your $$ until you read the article. Its title was
Windows 7 on multicore: How much faster?
but the subtitle really sums it up:
Microsoft has been touting its superior handling of threads in Windows 7. InfoWorld's tests show that speed isn't the only benefit, or necessarily the main one
You can read it here
http://www.infoworld.com/d/windows/wind ... 2009-10-21
but frankly the differences were quite underwhelming. Here's a telling quote:
The Cinebench benchmark is a ratio that measures how much faster the multiple threads are than running the benchmark with one thread; it's a true measure of how the threading scales when measured by rendering performance. Cinebench showed negligible differences in performance across the three operating systems
lneisenman
Posts: 20
Joined: Wed Dec 16, 2009 10:26 am

Re: Neuron as python module in windows 7

Post by lneisenman »

I followed the above directions and can now run python and successfully import Neuron. However, when I run in a directory with a nrnmech.dll file or run in another directory and try to use h.nrn_load_dll(), I get a popup with the following error:
The procedure entry point _nmodlmutex could not be located in the dynamic link library nrniv.dll
I also get a message stating:
loading membrane mechanisms from nrnmech.dll
LoadLibrary("nrnmech.dll") failed with error 127
dlopen failed -
I am using WindowsXP and Python 2.5.4 from the Enthough Python Distribution (both 32-bit). I am using Neuron 7.1 and have installed using the standard windows installer in addition to building from the source code. I used the mknrndll that came with the standard installation to build the nrnmech.dll file and am able to run simulations using mechanisms from the dll using nrngui-python from the standard installation. Any suggestions about what I am missing? Thanks in advance for your help.

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

Re: Neuron as python module in windows 7

Post by hines »

I am using WindowsXP and Python 2.5.4 from the Enthough Python Distribution (both 32-bit).
The installer for 7.1 is a cygwin version. Enthought requires a mingw version. When you build
from the source code, did you build against cygwin or mingw? It turns out there is a
http://www.neuron.yale.edu/ftp/neuron/v ... _setup.exe
and you should try that and see if the h.nrn_load.dll problem goes away.

On my laptop, I installed the above nrn71epd_setup.exe and then in a command prompt window
renamed c:\nrn71\bin hocmodule.dll to hoc.pyd and moved that and nrniv.dll into
c:\nrn71\lib\python\neuron (you could move them into c:\Python25 as well or any place that python
can find them. Then
set PYTHONPATH=c:/nrn71/lib/python
set NEURONHOME=c:/nrn71
Then I launched c:\Python25\python with c:\ as my working directory and the following worked:
from neuron import h
h.nrn_load_dll('c:/nrn71/demo/release/nrnmech.dll')
lneisenman
Posts: 20
Joined: Wed Dec 16, 2009 10:26 am

Re: Neuron as python module in windows 7

Post by lneisenman »

Thanks for the rapid response. I installed the nrn71epd version that you suggested and then was able to successfully
from neuron import h
h.nrn_load_dll('c:/nrn71/demo/release/nrnmech.dll')

However, I still could not load the dll I had previously created. The mknrndll in the nrn71epd version did not work for me, I think because this version does not include the gui. I ended up removing the nrn71epd version and reinstalling the standard nrn71 for windows. I then copied the hoc.pyd and nrniv.dll files from the marshalnrn/nrn/bin directory I had previously created using the above instructions to my c:/python25 directory. This got me back to where I started. I found I was able to successfully load the demo/release/nrnmech.dll from the marshalnrn/nrn directory. I hypothesized that dll's created using the standard installation are not compatible with the Neuron extension for python.

To try to get around this I did the following. I copied c:/nrn71/lib/hoc/mknrndll.hoc to c:/nrn71/lib/hoc/mknrnpydll.hoc and edited to contain the following code:

Code: Select all

xpanel("")
xbutton("nothing", "print 1")
xpanel(5000, 5000)

show_winio(0)

{load_file("stdlib.hoc", "String")}

objref rwl_, rwf_, sf_, tobj, box
objref ldfile
strdef tstr, rwdname, path

sprint(path, "%s", getcwd())
ldfile = new File()

sf_ = new StringFunctions()
if (unix_mac_pc() == 1) {
	rwdname = "$(HOME)/.NRNWorkingDirs"
}else{
	rwdname = "$(NEURONHOME)/RecentWorkingDirs"
}

proc filemenu() {
	box = new VBox()
	box.intercept(1)
	xpanel("")
	xmenu("Recent directories", "recent_working_dirs()")
	xmenu()
	xpanel()
	box.intercept(0)
}

proc doit() {local b
	filemenu()
	while (1) {
		index = -1
		b = box.dialog("Choose directory (containing .mod files) for creating nrnmech.dll", "Choose directory", "Quit")
		if (b == 0) { break }
		if (index != -1) {
			chdir(rwl_.object(index).s)
		}
		change_working_dir()
	}
	quit()
}

proc change_working_dir() {
	ldfile.chooser("d", "Directory", "", "Make nrnmech.dll", "Cancel", getcwd())
	if (ldfile.chooser()) {
		read_recent_working_dirs()
		if (change_working_dir1(ldfile.dir)) {
			exec()
		}
	}
}

func change_working_dir1() {
	if(chdir($s1) != 0) {
		sprint(tstr, "No such directory: %s", $s1)
		continue_dialog(tstr)
		return 0
	}
	sprint(path, "%s", getcwd())
	write_recent_working_dirs()
	return 1
}

proc read_recent_working_dirs() {local i
	rwf_ = new File()
	rwl_ = new List()
	if (rwf_.ropen(rwdname)) {
		while (!rwf_.eof()) {
			rwf_.gets(tstr)
			sf_.left(tstr, sf_.len(tstr) - 1)
			tobj = new String(tstr)
			rwl_.append(tobj)
		}
		rwf_.close()
	}
}

proc write_recent_working_dirs() {local i
	rwf_ = new File()
	if (rwf_.wopen(rwdname)) {
		rwf_.printf("%s\n", path)
		for i=0, rwl_.count-1 {
			if (strcmp(path, rwl_.object(i).s) != 0) {
				rwf_.printf("%s\n", rwl_.object(i).s)
				if (i > 10) break
			}
		}
		rwf_.close()
	}
}

proc recent_working_dirs() {local i
	read_recent_working_dirs()
	for i=0, rwl_.count-1 {
		//sprint(tstr, "change_working_dir2(%d)", i)
		sprint(tstr, "index=%d box.unmap(1)", i)
		xbutton(rwl_.object(i).s, tstr)
	}
}

strdef marshal
marshal = "c:/marshalnrn/nrn"

proc exec() {
	chdir(path)
	sprint(tstr, "%s/bin/rxvt -e %s/bin/sh %s/lib/mknrndll.sh %s", marshal, marshal, marshal, marshal)
	print tstr

	WinExec(tstr)
	quit()
}

doit()
compared to the original file, I added lines 105 and 106 which define the string "marshal" as "c:/marshalnrn/nrn" and in line 110 I replaced the four instances of "neuronhome()" with "marshal"

I then copied the mknrndll shortcut in .../Start Menu/Programs/NEURON7.1 to mknrnpydll and edited it to point to the mknrnpydll.hoc file. Finally I had to copy the gcc-3.exe file from c:/cygwin/bin to c:/marshalnrn/nrn/bin and rename it gcc.exe.

I created a dll using my mknrnpydll which I was successfully able to load using "from neuron import h" after running python in the directory containing the dll. Much to my surprise, the same dll seems to work with nrngui and nrngui-python from the standard distribution. Is there any reason to think any of this will cause other problems?

Thanks again

Larry
Post Reply