Building Neuron under Win7 with a custom Python installation

Post Reply
somada141

Building Neuron under Win7 with a custom Python installation

Post by somada141 »

Hi all,

I am trying to build the Neuron 7.1 source as a Python module for my own custom Python installation under Windows 7.

After spending more than 20 hours struggling with this and after going through all relevant posts in the forum (which are inconclusive for the most part) I decided to take a shot in the forum myself.

So, what I did:

1)Install Cygwin according to the instructions here: http://www.neuron.yale.edu/neuron/download/getcygwin . I downloaded cygwin and properly installed all the required packages as outlined in the link above. The whole procedure seems to work fine and no errors were observed.

2)Downloaded the source for both InterViews and Neuron from here: http://www.neuron.yale.edu/neuron/download/getstd
3)Copied the tarballs in my newly created HOME directory under my user folder in the Cygwin directory
4)Based on the instructions by Andrew Davison here: http://www.davison.webfactional.com/not ... on-python/ and the various posts I found in the forum I did the following:
a)Go to the directory where neuron is extracted
b)I have managed configuring and making InterViews but in this case I will only write the steps without IV (have tried them out as well on a different machine)
c)I configure neuron. I have tried a ton of different configurations mentioned here in the forum to no avail. If I do not use python then the configure works, however no configuration that includes python works:

This one (no Python) works:

Code: Select all

./configure --prefix=`pwd` --without-iv
The 'configure' stage finishes ok but it does not include python (so what's the point) and during the 'make' stage an error asking for a 'mingw-targeted cross-compiler' occurs

In order to avoid the above error and include python I have tried the following:

Code: Select all

./configure --prefix=`pwd` --without-iv --disable-cygwin --with-nrnpython
which tries to use cygwin's own python installation and gives the following error:

Code: Select all

configure:20517: error: could not run a test that used the python library.
Examine config.log to see error details. Something wrong with
	PYLIB=-L/usr/lib/python2.5/config -lpython2.5 -ldl  -R/usr/lib/python2.5/config
or
	PYLIBDIR=/usr/lib/python2.5/config
or
	PYLIBLINK=-L/usr/lib/python2.5/config -lpython2.5 -ldl
or
	PYINCDIR=/usr/include/python2.5
I also tried this:

Code: Select all

./configure --prefix=`pwd` --without-iv --without-memacs --with-readline=no --without-nmodl --disable-cygwin --with-nrnpython
which gives the above error as well

Lastly, I tried this one where I try to link to my 'custom' installation which a 2.6 python version, part of the Enthought Distribution 32bit package:

Code: Select all

./configure --prefix=`pwd` --without-iv --disable-cygwin --with-nrnpython=/cygdrive/c/Python26/python PYLIBDIR=/cygdrive/c/Python26/libs PYINCDIR=/cygdrive/c/Python26/include PYLIBLINK="-L/cygdrive/c/Python26/libs -lpython26 -ldl" PYLIB="-L/cygdrive/c/Python26/libs -lpython26 -ldl"
which gives this error:

Code: Select all

configure:20517: 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/Python26/libs -lpython26 -ldl
or
	PYLIBDIR=/cygdrive/c/Python26/libs
or
	PYLIBLINK=-L/cygdrive/c/Python26/libs -lpython26 -ldl
or
	PYINCDIR=/cygdrive/c/Python26/include
Of course I checked the log file as it says above. It seems that the 'configure' executable cannot manage to link to the Python library for some reason because its trying to run a simple test of pythonic integration in C++ but it fails. The relevant part of the log is:

Code: Select all

configure:20484: $? = 1
configure: failed program was:
| /* confdefs.h.  */
| 
| #define PACKAGE_NAME "nrn"
| #define PACKAGE_TARNAME "nrn"
| #define PACKAGE_VERSION "7.1"
| #define PACKAGE_STRING "nrn 7.1"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE "nrn"
| #define VERSION "7.1"
| #define DISCRETE_EVENT_OBSERVER 1
| #ifdef __cplusplus
| extern "C" void exit (int);
| #endif
| #define IVOS_DECLARE_TRUE
| #define YYTEXT_POINTER 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define USE_PYTHON 1
| /* end confdefs.h.  */
| 
| #include <Python.h>
| 
| int
| main ()
| {
| 
| 	Py_Initialize();
| 	Py_Finalize();
| 	return 0;
| 
|   ;
|   return 0;
| }
configure:20517: 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/Python26/libs -lpython26 -ldl
or
	PYLIBDIR=/cygdrive/c/Python26/libs
or
	PYLIBLINK=-L/cygdrive/c/Python26/libs -lpython26 -ldl
or
	PYINCDIR=/cygdrive/c/Python26/include
So none of the above 3 works. I have tried this procedure on two different win7 machines with different Python installations & versions (namely 2.5 and 2.6) but the result is always the same.

Of course I have checked the paths and they work fine. Actually if I just write 'python' in the cygwin console, python opens up normally.

Is there something I am missing? Is there some magical way to get Neuron to build under Windows with Python? I should note that I tried to configure and build the same code under an Ubuntu box and it seems to work fine.

Any help, comments, suggestions or advice of any sort will be appreciated :D
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Building Neuron under Win7 with a custom Python installation

Post by hines »

I assume you are trying to build a version that works with the enthought
python distribution.

A few months ago cygwin changed in some fundamental ways. In particular
the cygwin compiler no longer supports the -mnocygwin flag and instead
an mswin native version that does not use the cygwin1.dll must be built
using the MinGW compilers. Fortunately the mingw compilers come with
the enthought distribution so you do not have to install them
separately. There were many other changes as well to cygwin 7 that
broke NEURON and so one must use the current hg repository version
http://www.neuron.yale.edu/hg/neuron/nrn/ or a recent nrn*.tar.gz file
at http://www.neuron.yale.edu/ftp/neuron/versions/alpha/

The --without-iv option must be used for configure since InterViews
cannot be compiled without cygwin at this time.

NEURON needs to be compiled in two phases. I.e. some programs need to run
under cygwin, and NEURON itself needs to run under MinGW. I configure
in an object directory (nrnepd) at the same level as the nrn source directory

../nrn/configure --prefix=`pwd` --without-iv --with-nmodl-only
make

export PATH=$HOME/bin:/cygdrive/c/Python26/Scripts:$PATH
cp /bin/make $HOME/bin/make
note that the enthought 'make' gives an error when building NEURON because
it cannot find nrnepd/src/nmodl/nocmodl.exe. I guess you would not have that
problem if you build in the nrn directory where the sources are.

../nrn/configure --prefix=`pwd` --without-iv --without-memacs --without-nmodl \
--disable-cygwin --with-nrnpython=/cygdrive/c/Python26/python \
PYINCDIR=c:/Python26/include PYLIB='-Lc:/Python26/libs -lpython26' \
PYLIBDIR=c:/Python26/libs PYLIBLINK='-Lc:/Python26/libs -lpython26' \
use_pthreads=no
make
make mswin

cd /cygdrive/c/marshalnrn/nrn/bin
cp hocmodule.dll hoc.pyd

Now in a dos prompt you can
set NEURONHOME=c:/marshalnrn/nrn
set PYTHONPATH=c:/marshalnrn/nrn/lib/python;c:/marshalnrn/nrn/bin
c:\Python26\python
from neuron import h
somada141

Re: Building Neuron under Win7 with a custom Python installation

Post by somada141 »

Hi Michael,

First of all let me thank you for your prompt reply.

I went through your instructions but I still have problems.

Let me tell you what I did:
1)Under the HOME dir I created a 'nrnepd' directory which is in the same level as the 'nrn-7.2' directory containing all the neuron source and files (as extracted from the tar)
2)I then follow your instruction. Up to the point where I build 'nmodl' everything seems to work

However, afterwards problems show up. What is it that you accomplish with these two lines? :

Code: Select all

export PATH=$HOME/bin:/cygdrive/c/Python26/Scripts:$PATH
cp /bin/make $HOME/bin/make
From what I understood you are adding two paths to the PATH variable, one to a 'bin' folder under the HOME directory and the path to the scripts folder under the EPD directory which contains the MinGW compilers. However, in the cygwin installation, there is no 'bin' folder under the home directory so these lines fail to execute. I tried creating an empty 'bin' folder under my HOME directory which allows the above lines to work but then exhibits another problem.

When I follow your instructions (having created a new bin folder as mentioned above) then the configuration of Neuron fails with this error:

This is the command I used (as shown in the config.log):

Code: Select all

  ../nrn-7.2/configure --prefix=/home/Adam/neuron/nrnepd --without-iv --without-memacs --without-nmodl --disable-cygwin --with-nrnpython=/cygdrive/c/Python26/python PYINCDIR=c:/Python26/include PYLIB=-Lc:/Python26/libs -lpython26 PYLIBDIR=c:/Python26/libs PYLIBLINK=-Lc:/Python26/libs -lpython26 use_pthreads=no
and this is the error that shows up (again from the log):

Code: Select all

cc version 3.4.5 (mingw special)
configure:2682: $? = 0
configure:2684: g++ -V </dev/null >&5
epd-g++.exe: `-V' option must have argument
configure:2687: $? = 1
configure:2710: checking for C++ compiler default output file name
configure:2713: g++    conftest.cc  >&5

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
configure:2716: $? = 3
configure: failed program was:
| /* confdefs.h.  */
| 
| #define PACKAGE_NAME "nrn"
| #define PACKAGE_TARNAME "nrn"
| #define PACKAGE_VERSION "7.2"
| #define PACKAGE_STRING "nrn 7.2"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE "nrn"
| #define VERSION "7.2"
| #define DISCRETE_EVENT_OBSERVER 1
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:2755: error: C++ compiler cannot create executables
See `config.log' for more details.
Do you have any idea why this happens?

Also I should mention that ultimately I want to include Neuron in our own software which has its own python distribution without its own mingw compilers. Would it be possible to do the above procedure for our pythonic distribution (perhaps through copying the mingw executables from the EPD to our distribution or using the EPD to build Neuron but link it to our own distribution)?

Thanks in advance for your help,
Adam
somada141

Re: Building Neuron under Win7 with a custom Python installation

Post by somada141 »

Anyone?
I am sure this will be of further use from others, I can't be the only one struggling with this...

Any help will be appreciated

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

Re: Building Neuron under Win7 with a custom Python installation

Post by hines »

Sorry. I forgot to subscribe to the topic.
The purpose of the two paths is so that make is the normal cygwin make (the first path)
and that the epd mingw compilers are used (the second path).
Ultimately you should install mingw as described at
http://www.mingw.org/wiki/HOWTO_Install ... iler_Suite
about a third of the way down that file is
"
Manual Installation

Instead of using an installer you can as well get all required packets and unpack them manually into a subdirectory. In fact that's what this writer is doing himself
"

With regard to your configure problem:

Code: Select all

configure:2713: g++    conftest.cc  >&5

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information
That is a killer.
You need to verify that your (enthought mingw) compiler works.
Test it manually by creating the program
test.cpp
-----------
int main() { return 0; }
----------
then run
g++ test.cpp
Does it fail or succeed. (make sure your gcc is the mingw (due to the second path above) and not the cygwin , I presume cygwin will of course work as well).
If it fails, I would install the mingw mentioned above.
somada141

Re: Building Neuron under Win7 with a custom Python installation

Post by somada141 »

Hi again,

Sorry for not replying, have been preoccupied with other projects for a while now. It turns out all the mingw compilers failed when used through Cygwin while they worked fine on their own (when used through the command prompt). The reason was that there was no TEMP enviroment variable set under the cygwin enviroment and the compiler crashed. The solution is to set it manually like that:

Code: Select all

export TEMP=/tmp
the problem is debated in the link below and the above solution worked.

http://stackoverflow.com/questions/2151 ... -terminate

So now the mingw compilers (both the EPD and the ones I installed manually seem to work fine).

I'll do the whole procedure all over again and see where it takes me. Once I run into other problems or if I finally manage to build the thing I'll come back here to either bug you for further assistance or to write a mini-guide on how to do this thing.

cheers,
Adam
Post Reply