Python cannot import neuron library on Windows install

Post Reply
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Python cannot import neuron library on Windows install

Post by pascal »

I'm having trouble installing NEURON 8.2 on Windows 11. I installed NEURON 8.2 using the installer from the website, then installed Anaconda. When I open Python and type from neuron import h, I get this:

Traceback (most recent call last):
File "c:\nrn\lib\python\neuron\__init__.py", line 135, in <module>
from . import hoc
ImportError: cannot import name 'hoc' from partially initialized module 'neuron' (most likely due to a circular import) (c:\nrn\lib\python\neuron\__init__.py)

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 137, in <module>
import neuron.hoc
ModuleNotFoundError: No module named 'neuron.hoc'
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Python cannot import neuron library on Windows install

Post by ted »

Uninstall NEURON, then reinstall it.
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Python cannot import neuron library on Windows install

Post by pascal »

Uninstalled, reinstalled, restarted...still the exact same error message.
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Python cannot import neuron library on Windows install

Post by pascal »

All right, finally got it working. I uninstalled both NEURON and Anaconda. I then re-installed them, but installed Anaconda first, and NEURON second. (Before, the order was reversed.) I'm not sure why, but the order of installation seemed to matter, at least in my case.
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Python cannot import neuron library on Windows install

Post by ted »

Thanks for the followup on that. I always adivse users to install Python first, then NEURON. The fact that you had to uninstall both, then install Python, and finally NEURON, doubtless contains a clue . . . if we're smart enough to figure out what it might be.
patoorio
Posts: 87
Joined: Wed Jan 30, 2008 12:46 pm

Re: Python cannot import neuron library on Windows install

Post by patoorio »

Hi,

I am having the same issue with my Python/Windows installation:

Code: Select all

from neuron import h
Traceback (most recent call last):

  File c:\nrn\lib\python\neuron\__init__.py:135
    from . import hoc

ImportError: cannot import name 'hoc' from partially initialized module 'neuron' (most likely due to a circular import) (c:\nrn\lib\python\neuron\__init__.py)


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  Cell In[1], line 1
    from neuron import h

  File c:\nrn\lib\python\neuron\__init__.py:137
    import neuron.hoc

ModuleNotFoundError: No module named 'neuron.hoc'
I uninstalled everything, then installed Python (miniconda) and finally Neuron. But the error arised again.
Looking at the C:\nrn\lib\python\neuron folder, I noticed the following files:

Code: Select all

hoc.cp37-win_amd64.pyd
hoc.cp38-win_amd64.pyd
hoc.cp39-win_amd64.pyd
hoc.cp310-win_amd64.pyd
hoc.cp311-win_amd64.pyd
But no 'cp312' file. However, I am using Python 3.12. Is it possible that the current version of Neuron is not meant to work with Python 3.12? (although under the Windows Subsystem for Linux it DOES run perfectly with Python 3.12).
What else can be happening? I took care of cleaning as much hidden folders and configuration files as I could before reinstalling everything.
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Python cannot import neuron library on Windows install

Post by pascal »

I just had this issue crop up again as well. Good catch with the Python version number. Like you, with Python 3.12 I could not import neuron. But then I reverted to Python 3.9, and this solved the problem. Are you able to simply go back to an earlier Python version, at least until they update NEURON to handle Python 3.12?
patoorio
Posts: 87
Joined: Wed Jan 30, 2008 12:46 pm

Re: Python cannot import neuron library on Windows install

Post by patoorio »

Yes, I thought about setting an environment with Python 3.11, but since I already have Python(3.12)+Neuron working under the WSL, it is kind of the same.
We'll have to wait for an update, I guess.

EDIT: in another computer I have Python 3.11 + Neuron working perfectly in Windows
adityaasopa
Posts: 1
Joined: Sat Oct 12, 2024 2:08 am

Re: Python cannot import neuron library on Windows install

Post by adityaasopa »

Can someone elaborate on why do we need conda and neuron.exe GUI installer to use NEURON on windows and in some particular order (first Conda then NEURON)?

I use "python venv" as environment manager, not conda and haven't been able to get neuron to work.
hines
Site Admin
Posts: 1706
Joined: Wed May 18, 2005 3:32 pm

Re: Python cannot import neuron library on Windows install

Post by hines »

NEURON + python can work only if the python version is one of those listed in the name of the neuron installer. Presently the installer one gets from
https://nrn.readthedocs.io/en/latest/ or https://nrn.readthedocs.io/en/8.2.6/ is
https://github.com/neuronsimulator/nrn/ ... -setup.exe nrn-8.2.6.w64-mingw-py-38-39-310-311-312-setup.exe

However if one goes back a bit more to https://nrn.readthedocs.io/en/8.2.4/ then one sees
https://github.com/neuronsimulator/nrn/ ... -setup.exe nrn-8.2.4.w64-mingw-py-37-38-39-310-311-setup.exe

If you have lost track of the installer name, then, as indicated above, you can see the list of neuron+python interface libraries at c:/nrn/lib/python/neuron that begin and end with hoc.cp...win.amd64.pyd

It is not supposed to matter whether Anaconda Python or NEURON is installed first. The reason I expect it to work is because the neuron installer sets PYTHONPATH which allows python to find neuron for import. If this continues to be a problem (even though the hoc.cp...pyd interface file exists for your python version) then I'll need to work with you to diagnose and fix the problem.
Post Reply