PyNEURON simplify NEURON usage from Python on Windows

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

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

PyNEURON simplify NEURON usage from Python on Windows

Post by uri.cohen » Sat Feb 11, 2012 3:36 am

It is now possible to use NEURON from python on Windows without installing NEURON and without compiling it from sources.
A new Python package called PyNEURON is available at pypi. If you have Python 2.7 installed on your Windows, just do the following:

Code: Select all

pip install PyNEURON
And you have a fully functional NEURON in Python, including support for compiling mechanism files!

Code: Select all

C:\>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
>>>
This will allow for building Python applications on top of NEURON without requiring the users to install NEURON themselves and may be great for education purposes.

Read all about it at https://bitbucket.org/uric/pyneuron/

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by hines » Tue Feb 14, 2012 7:00 am

Thanks very much Uri. That attains the simplicity of installation that I've been wishing for.
I've briefly looked into how you packaged a version for pip and and noticed that the zip file
contains both 32 and 64 bit dll's. I'm curious if 'pip install' sends enough info to be able to
steer to specific linux32/64, mac, mswin32/64 zip files, or if the user would have to
encode this in the PyNEURON name. I'll have to read about it in more detail.

I should mention that I'm finally able to build pure mswin InterViews + Python + NEURON
under i686-pc-mingw32 and x86_64-w64-mingw32 . An example of the latter is
http://www.neuron.yale.edu/ftp/neuron/v ... x86_64.exe
The installer would only be about 4MB in size if the compiler components for mknrndll didn't bloat it up
to 16MB.

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by uri.cohen » Tue Feb 14, 2012 7:15 am

I my implementation it is setup.py which install the right files (32/64) and possibly even MSWin / Mac / Linux is such a support will be added in the future (only MSwin is available there right now). I believe my solution for compiling the code using cygwin/mingw is similar yours and indeed also the size of my package has grown from few MB to 20 due to the need to correctly compile MOD files... :)

If you approve of my approach, maybe we can co-release NEURON and PyNEURON (when 7.3 is due) and even add a reference to PyNEURON in your documentation.

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by hines » Tue Feb 14, 2012 8:58 am

yes. It sounds good to me to do a co-release when 7.3 is made the standard distribution. That is in the indefinite future with
no target date. For now, we will add the relevant info about PyNEURON 7.2 to the NEURON web site install pages.

The build of the setup.exe I mentioned is done entirely within a MinGW MSYS envirionment using gcc4.7 and seems to
be about twice as fast as building under cygwin. MinGW installation is not as simple as a Cygwin environment but is much
less in size and install time as well. I have notes about it in the nrn/howtomingw but they are quite disorganized and I'll need
to edit that when I attempt to reproduce from a bare machine. Unfortunately the mingw bash terminal is very much less functional
than cygwins' rxvt bash terminal in the area of mouse copy/paste so I'm still using the cygwin terminal for a few administrative things
such as mercurial.

I wondered, though perhaps it may be more tedious than it is worth, if it would be possible for the PyNEURON.zip file
to have basically just a setup.py and all the common files which, after it was run on the user machine, could figure out which machine specific things
were needed and then download and install just the items needed. For example, if the enthought python distribution is already installed, it seems likely that
there is already enough MinGW build environment available for mknrndll.

vellamike

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by vellamike » Tue Feb 21, 2012 10:42 am

For whoever is interested in the same thing on Linux please see:

http://www.srcf.ucam.org/~mv333/wordpress/

vladimirov
Posts: 50
Joined: Thu Jul 07, 2011 6:20 pm

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by vladimirov » Mon Apr 16, 2012 7:17 pm

Hi, Uri,
Thanks a lot for the PyNEURON. I just noticed on PyNEURON site that the link to installation instructions is broken due to a typo (https://bitbucket.org/uric/pyneuron/wiki/Instalation), double "l" in "Installation" is missing.

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by uri.cohen » Tue Apr 17, 2012 11:24 am

Thanks, fixed.

patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by patoorio » Thu May 10, 2012 12:13 pm

Thanks a lot Uri for PyNEURON.
I'm trying to set it up. I'm using Python 2.7, 64-bit because I don't care (yet) about compiling (I can compile with the standar 32-bit neuron, right? ... or maybe the compiled dll will not work with the 64 bit python??).
Nevertheless, I have not been able to get to check that because I'm getting the "No module named hoc" error:

Code: Select all

C:\>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from neuron import h
Found NEURON at C:\Python27\neuronhome
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\neuron\__init__.py", line 116, in <module>

    import neuron.hoc
ImportError: No module named hoc
I have set the NEURONHOME environment variable to C:\Python27\neurohome
I'm using Windows 7 64-bit, but now I'm really intrigued about the sentence "Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32" that appears upon startin python.
Any clue?

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by uri.cohen » Thu May 10, 2012 6:35 pm

The sentence about win32 is just referring to the Win32 API of windows, not to the fact that it's 32bit (historical name). Your python is indeed 64bit, and note that 32bit DLLs cannot be loaded into 64bit processes, hence you won't be able to use any mechanism.
Regarding your problem, do you see hoc.pyd in C:\Python27\neuronhome\bin? If you do, try to add it to Windows path variable and see if it solves the problem.

Code: Select all

set path=%path%;C:\Python27\neuronhome\bin

patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by patoorio » Fri May 11, 2012 5:40 pm

Yes, the file is located in C:\Python27\neuronhome\bin
I added the path to the environment variable but it didn't work

Code: Select all

C:\>path
PATH=C:\Program Files\MiKTeX 2.9\miktex\bin\x64;C:\Program (...) ;C:\Program Files
\gs\gs8.64\bin;C:\Python27;C:\Python27\neuronhome\bin

C:\>python
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from neuron import h
Found NEURON at C:\Python27\neuronhome
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\neuron\__init__.py", line 116, in <module>

    import neuron.hoc
ImportError: No module named hoc
>>>
I'm going to try with the 32bit version (because I will have to use it anyway) to see if I get the same.
Can I have both 32-bit and 64-bit python installed at the same time? How do I tell windows to launch one or the other?

Regards.

patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by patoorio » Mon May 14, 2012 11:37 am

OK, with 32bit python it worked at the first try.
So the problem limits to the 64-bit version.

Regards

tittbit

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by tittbit » Sun May 20, 2012 2:35 pm

is there any fix for 64 bit,

does anyone knows??

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

Re: PyNEURON simplify NEURON usage from Python on Windows

Post by hines » Sun May 20, 2012 2:58 pm

The current status is as indicated in the thread:
http://www.neuron.yale.edu/phpBB/viewto ... f=5&t=2604

Post Reply