Python NEURON

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

Moderator: hines

FariaVS
Posts: 9
Joined: Wed Feb 08, 2017 9:06 am

Python NEURON

Post by FariaVS » Sat Apr 01, 2017 1:28 pm

'I have NEURON 7.4 installed, Python 3.6, Anaconda, I have already configured system variables, I am using Windows 10.
But I can not use Python with NEURON.

Why?

In this tutorial you have this command to import NEURON into Python

'From neuron import h, gui'

Why do not you charge?

bwjmbb17
Posts: 16
Joined: Mon Apr 10, 2017 10:09 am

Re: Python NEURON

Post by bwjmbb17 » Tue May 02, 2017 5:07 pm

I believe you need to have the python 2.7 version of anaconda installed for NEURON to work with python properly.

-bwjmbb17

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

Re: Python NEURON

Post by hines » Tue May 02, 2017 6:54 pm

At present the neuron setup.exe installer is limited to python 2. I can create a neuron setup.exe installer that works for python 3 but for simplicity my near term goal is to make a single installer that works with either python2 or python3. Hopefully that will be ready in about a month.

I am presently attempting to make the setup.exe installer more robust for windows 10 and either enthought canopy or anaconda and allowing launch either of nrniv or python that allows "import neuron". Issues that have recently arisen are that windows10 + enthought seems to require a full path to load the nrnmech.dll . In some environments c:/nrn/bin/libstd++-6.dll needs to be copied to c:/nrn/lib/python/neuron in order for a launch of python to successfully import neuron. And under some circumstances, when the user chooses to create some DOS environement variables for PYTHONPATH, the dos format can interfere with the ability of a launch of python to import neuron.

These have all been, I hope, resolved in general and I will be putting a new setup.exe in the alpha site in a day or so. Although I am still testing with different windows 10 environments, you may wish to try
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe

xzc
Posts: 5
Joined: Fri May 19, 2017 4:59 am

Re: Python NEURON

Post by xzc » Sun May 21, 2017 10:07 pm

I also used Python 3.5, Anaconda and win 10, I have tried http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe, but I still can not use Python with NEURON.
So I have a question about whether there is a new version suitable for Python3?
hines wrote:At present the neuron setup.exe installer is limited to python 2. I can create a neuron setup.exe installer that works for python 3 but for simplicity my near term goal is to make a single installer that works with either python2 or python3. Hopefully that will be ready in about a month.

I am presently attempting to make the setup.exe installer more robust for windows 10 and either enthought canopy or anaconda and allowing launch either of nrniv or python that allows "import neuron". Issues that have recently arisen are that windows10 + enthought seems to require a full path to load the nrnmech.dll . In some environments c:/nrn/bin/libstd++-6.dll needs to be copied to c:/nrn/lib/python/neuron in order for a launch of python to successfully import neuron. And under some circumstances, when the user chooses to create some DOS environement variables for PYTHONPATH, the dos format can interfere with the ability of a launch of python to import neuron.

These have all been, I hope, resolved in general and I will be putting a new setup.exe in the alpha site in a day or so. Although I am still testing with different windows 10 environments, you may wish to try
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe

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

Re: Python NEURON

Post by hines » Mon May 22, 2017 7:38 am

The nrn-7.5.master-1570 installer for windows is also restricted to Python2.
I am now able to build a generic version of the nrn installer on linux for Python2 and 3.x but my virtualbox win7 guest where I prepare windows installers was so far behind on updates that
I could not install python3. All attempts to update that vbox guest have failed and i have to start from scratch. I hope to have an installer uploaded to the alpha folder in a few weeks.

xzc
Posts: 5
Joined: Fri May 19, 2017 4:59 am

Re: Python NEURON

Post by xzc » Mon May 22, 2017 9:52 pm

Thans for your reply!And I am looking forward to your good news.
hines wrote:The nrn-7.5.master-1570 installer for windows is also restricted to Python2.
I am now able to build a generic version of the nrn installer on linux for Python2 and 3.x but my virtualbox win7 guest where I prepare windows installers was so far behind on updates that
I could not install python3. All attempts to update that vbox guest have failed and i have to start from scratch. I hope to have an installer uploaded to the alpha folder in a few weeks.

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

Re: Python NEURON

Post by hines » Thu Jun 01, 2017 6:11 pm

http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
is my first attempt at an installer that will work with either python2 or python3. The latter was built against the
include files for python3.6 but there is a chance it will work for python3.5 as well. Future builds will use
#define PY_LIMITED_API
which should make it compatibie with python3.[2-6] . The python2 portion should work with any python2.[5-7].

Things are expected to work if you start a bash terminal and try
python
import neuron

launching nrniv will likely require a proper PYTHONHOME and perhaps a NRN_PYLIB environment variable. For example, on my virtualbox win6-64 guest with an standard python installation in
e:/python27 and e:/python36, for python3 to launch python and import neuron I need
export PATH=/e/python36:$PATH
wheras to launch nrniv -python and import neuron, I need
export PYTHONHOME=/e/python36
export NRN_PYLIB=/e/python36/python36.dll

xzc
Posts: 5
Joined: Fri May 19, 2017 4:59 am

Re: Python NEURON

Post by xzc » Thu Jun 01, 2017 10:18 pm

I have tried the new version, it does not work for python3.5. And I met the problem as following
"Path not updated,original length 1036>1024"
hines wrote:http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
is my first attempt at an installer that will work with either python2 or python3. The latter was built against the
include files for python3.6 but there is a chance it will work for python3.5 as well. Future builds will use
#define PY_LIMITED_API
which should make it compatibie with python3.[2-6] . The python2 portion should work with any python2.[5-7].

Things are expected to work if you start a bash terminal and try
python
import neuron

launching nrniv will likely require a proper PYTHONHOME and perhaps a NRN_PYLIB environment variable. For example, on my virtualbox win6-64 guest with an standard python installation in
e:/python27 and e:/python36, for python3 to launch python and import neuron I need
export PATH=/e/python36:$PATH
wheras to launch nrniv -python and import neuron, I need
export PYTHONHOME=/e/python36
export NRN_PYLIB=/e/python36/python36.dll

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

Re: Python NEURON

Post by hines » Fri Jun 02, 2017 3:37 pm

I need further info about the error. Did that occur when you ran the setup.exe installer? If so, you may not have space in the environment to set the dos path unless you reduce its present size (or else
do not check the "dos" box during installation)
Or did the error occur when you launched python and executed 'import neuron'?
Future builds will use
#define PY_LIMITED_API
The new version that may be safer for use with python3.x that differs from the one I used to build is now at
http://www.neuron.yale.edu/ftp/neuron/v ... gw32-setup.

xzc
Posts: 5
Joined: Fri May 19, 2017 4:59 am

Re: Python NEURON

Post by xzc » Tue Jun 06, 2017 5:11 am

The error "Path not updated,original length 1036>1024" is because of that I don't have enough space to set the dos path.
And I ran the new setup.exe installer,but when I lauched python and executed "import neuron", I met the error:
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import neuron
Traceback (most recent call last):
File "c:\nrn\lib\python\neuron\__init__.py", line 105, in <module>
import hoc
ImportError: No module named 'hoc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\nrn\lib\python\neuron\__init__.py", line 109, in <module>
import neuron.hoc
ImportError: No module named 'neuron.hoc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\nrn\lib\python\neuron\__init__.py", line 114, in <module>
import neuron.hoc3 as hoc
ImportError: DLL load failed:
hines wrote:I need further info about the error. Did that occur when you ran the setup.exe installer? If so, you may not have space in the environment to set the dos path unless you reduce its present size (or else
do not check the "dos" box during installation)
Or did the error occur when you launched python and executed 'import neuron'?
Future builds will use
#define PY_LIMITED_API
The new version that may be safer for use with python3.x that differs from the one I used to build is now at
http://www.neuron.yale.edu/ftp/neuron/v ... gw32-setup.

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

Re: Python NEURON

Post by hines » Tue Jun 06, 2017 10:12 am

I installed Anaconda3-4.1.1 and reproduced the problem. My dll's were linked against python36.dll and so my attempt to make a generic windows dll good for any python3.x is
flawed and i have to go back to the drawing board. It seems that it is necessary to build different dlls for each version of python3 that I wish to support.

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

Re: Python NEURON

Post by hines » Thu Jun 08, 2017 4:32 pm

Here is another attempt at getting a single installer that works with python 2.7, 3.5, and 3.6. The test
python -c 'import neuron ; neuron.test()'
works with those three versions of Anaconda except that importing rxd fails for 3.5. I will try to diagnose and fix that. I have not tested with enthought canopy.
Ironically, launching nrniv is more complicated environmentally than launching python. The latter needs only a PYTHONPATH
which is known during installation. But nrniv generally needs a PYTHONHOME and a NRN_PYLIB for python to work and figuring
out the latter has not been automated. For my installation of Anaconda2-4.3.1 on windows 10, to launch nrniv -python I needed
export PYTHONHOME="/c/users/michael hines/anaconda3"
export NRN_PYLIB="/c/users/michael hines/anaconda3/python35.dll"

http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe

Note that my tentative name convention enumerates the python versions that should work with this version of NEURON.

xzc
Posts: 5
Joined: Fri May 19, 2017 4:59 am

Re: Python NEURON

Post by xzc » Mon Jun 12, 2017 7:28 am

I have tried the new version,after setting the environment variable, it works with python3.5 except that importing rxd.
Thank you very much!
hines wrote:Here is another attempt at getting a single installer that works with python 2.7, 3.5, and 3.6. The test
python -c 'import neuron ; neuron.test()'
works with those three versions of Anaconda except that importing rxd fails for 3.5. I will try to diagnose and fix that. I have not tested with enthought canopy.
Ironically, launching nrniv is more complicated environmentally than launching python. The latter needs only a PYTHONPATH
which is known during installation. But nrniv generally needs a PYTHONHOME and a NRN_PYLIB for python to work and figuring
out the latter has not been automated. For my installation of Anaconda2-4.3.1 on windows 10, to launch nrniv -python I needed
export PYTHONHOME="/c/users/michael hines/anaconda3"
export NRN_PYLIB="/c/users/michael hines/anaconda3/python35.dll"

http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe

Note that my tentative name convention enumerates the python versions that should work with this version of NEURON.

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

Re: Python NEURON

Post by hines » Mon Jun 12, 2017 7:36 am

http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
automates the determination of NRN_PYLIB when a bash terminal is started. Unfortunately, I have been unable
to determine why 'import rxd' fails with anaconda python 3.5. Further diagnosis will reguire setting up a full
development environment along with that version of anaconda and probably a lot of experimentation.

cengique
Posts: 7
Joined: Thu Jun 09, 2011 7:22 pm

Re: Python NEURON

Post by cengique » Thu May 24, 2018 2:05 pm

hines wrote:
Mon Jun 12, 2017 7:36 am
http://www.neuron.yale.edu/ftp/neuron/v ... -setup.exe
automates the determination of NRN_PYLIB when a bash terminal is started. Unfortunately, I have been unable
to determine why 'import rxd' fails with anaconda python 3.5. Further diagnosis will reguire setting up a full
development environment along with that version of anaconda and probably a lot of experimentation.
We were able to get Anaconda 3.6 64-bit to work with Neuron 7.5 using your 1650 version on Windows 10. We downloaded it from the 7.5 folder on FTP: https://neuron.yale.edu/ftp/neuron/vers ... -setup.exe . The trick we had to do was uninstall all pyneuron packages in Anaconda, and then copy the lib/python/neuron folder from the Neuron installation to under Anaconda's lib/site-packages folder. After that, we were able to use "import neuron" in IDLE.

Post Reply