NeuralEnsemble / PyNN

A Python package for simulator-independent specification of neuronal network models.
Other
276 stars 126 forks source link

Cannot import pyNN.neuron in Windows #716

Closed cxr001 closed 2 years ago

cxr001 commented 3 years ago

After I compiled the "mod" files by mknrndll, the "simulator.py" in pyNN still could not find the right path to load these models. As in Windows, it makes my "nrnmech.dll" is in the same folder as my "mod" files, I rewrite the def load_mechanisms(path) in "simulator.py", add my path manually, as:

arch_list = [platform.machine(), 'i686', 'x86_64', 'powerpc', 'umac']
for arch in arch_list:
    lib_path = os.path.join(path, arch, '.libs', 'libnrnmech.so')
    lib_path2 = "************/site-packages/pyNN/neuron/nmodl/nrnmech.dll"
    if os.path.exists(lib_path):
        h.nrn_load_dll(lib_path)
        nrn_dll_loaded.append(path)
        return
    elif os.path.exists(lib_path2):
        h.nrn_load_dll(lib_path2)
        nrn_dll_loaded.append(path)
        return

So I can load these models. However, I still cannot import pyNN.neuron, it reports a error from "cells.py" as:

TypeError Traceback (most recent call last)

in ----> 1 import pyNN.neuron *******\lib\site-packages\pyNN\neuron\__init__.py in 21 from pyNN.neuron import simulator 22 from pyNN.neuron.random import NativeRNG ---> 23 from pyNN.neuron.standardmodels.cells import * 24 from pyNN.neuron.connectors import * 25 from pyNN.neuron.standardmodels.synapses import * *******\lib\site-packages\pyNN\neuron\standardmodels\cells.py in 9 10 from pyNN.standardmodels import cells as base_cells, build_translations ---> 11 from pyNN.neuron.cells import (StandardIF, SingleCompartmentTraub, 12 RandomSpikeSource, VectorSpikeSource, 13 RandomGammaSpikeSource, *******\lib\site-packages\pyNN\neuron\cells.py in 516 517 --> 518 class RandomSpikeSource(hclass(h.NetStimFD)): 519 520 parameter_names = ('start', '_interval', 'duration') *******\lib\python\neuron\hclass3.py in __init_subclass__(cls, hoc_type, **kwargs) 108 # with the arguments that have to be passed into `HocObject.__new__`. 109 # See https://github.com/neuronsimulator/nrn/issues/1129 --> 110 raise TypeError( 111 f"`{cls.__qualname__}` implements `__init__` but misses `__new__`. " 112 + "Class must implement `__new__`" TypeError: `RandomSpikeSource` implements `__init__` but misses `__new__`. Class must implement `__new__` and call `super().__new__` with the arguments required by HOC to construct the underlying h.NetStimFD() HOC object. I don't know how to solve this problem. I use PyNN-0.9.6 and NEURON 8.0. Platform is AMD64. Thanks
cxr001 commented 3 years ago

I can import pyNN.neuron after removing raise Error part in "hclass3.py"(line106 115)

apdavison commented 3 years ago

Many thanks for the bug report. It seems there are two issues, here. One is the load_mechanisms issue, the other seems like it may be due to changes in NEURON. To help debug the latter, would you be able to try using an older version of NEURON (7.x) and let me know what happens?

cxr001 commented 3 years ago

Yes, if trying NEURON(7.8), the second error will not appear

cxr001 commented 3 years ago

For load_mechanisms issue, NEURON path use '/', but os.path use \

Farzinkh commented 2 years ago

hi I have same problem with importing pyNN.neuron in windows 10 I have installed neuron 7.8 and 8 by installer with latest version of pyNN by pip command but still I cannot import it and this the error.

numprocs=1 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Anaconda\envs\brain\lib\site-packages\pyNN\neuron\__init__.py", line 21, in <module> from pyNN.neuron import simulator File "D:\Anaconda\envs\brain\lib\site-packages\pyNN\neuron\simulator.py", line 551, in <module> load_mechanisms(mech_path) # maintains a list of mechanisms that have already been imported File "D:\Anaconda\envs\brain\lib\site-packages\pyNN\neuron\simulator.py", line 72, in load_mechanisms raise IOError("NEURON mechanisms not found in %s. You may need to run 'nrnivmodl' in this directory." % path) OSError: NEURON mechanisms not found in D:\Anaconda\envs\brain\lib\site-packages\pyNN\neuron\nmodl. You may need to run 'nrnivmodl' in this directory.

running nrnivmodl in pyNN/neuron/nmodl dosen't help at all .

what am I doing wrong?

apdavison commented 2 years ago

I've tested this with Windows 11, Python 3.10, NEURON 8.2 and the current PyNN master branch, and import pyNN.neuron works without problems, so I think we've fixed the underlying problem.

Please comment if you're still encountering problems, and I'll reopen the ticket.