Search code examples
pythonvisual-studioneuron-simulator

Visual Studio 2019, Python and Neuron simulator


I have Visual Studio Community 2019 up and running. I am attempting to use Python with NEURON(7.2.536.15) package. I have the neuron package in my Python 3.7 (64 bit) environment. How do I load the neuron simulator into my Python Application?

The command: import neuron generates: No module named 'neuron' import NEURON generates: No module named 'NEURON'

How do I load the neuron simulator into VS Python


Solution

  • Short answer:

    You'll need to compile NEURON from source to make 'import neuron' work from Python. Even that might be marred in issues as the official NEURON site says this in its Win compilation page: 'The instructions here may or may not still work.'

    More detail:

    The pip packages 'neuron' and 'pyneuron' are identical and have been released by another set of devs (not main NEURON devs) to make it easier to import neuron module under Win. There seems to only be support for Python 2.7 (and only 32-bit?). See: https://bitbucket.org/uric/pyneuron/wiki/Home

    There have been some other attempts to allow 'from neuron import h' under Win: https://www.neuron.yale.edu/phpBB/viewtopic.php?t=2501

    https://www.neuron.yale.edu/phpBB/viewtopic.php?f=5&t=2604

    If you can switch to 32-bit Python 2.7, the package might still work for you.

    In general, however, if you need to use NEURON+Python under VS/Windows I can suggest some alternatives:

    Try launching NEURON with 'nrniv -python yourfile.py' command

    This method successfully imports the neuron module. The downside is that it launches NEURON first and then runs the script. There is no way to delay the loading of NEURON.

    Use a Ubuntu VM but edit files using Visual Studio via a VM network share

    This way you would use the most debugged version of NEURON but still have the advantages of using Visual Studio/Windows.

    For debugging, you'd need to set up python remote debugging (e.g.: https://donjayamanne.github.io/pythonVSCodeDocs/docs/debugging_remote-debugging/).

    If you will use this route, I have a tutorial on how to compile NEURON under Ubuntu and make sure it can import neuron from Python:

    https://neurojustas.wordpress.com/2018/03/27/tutorial-installing-neuron-simulator-with-python-on-ubuntu-linux/

    To make the network share work, I have another tutorial as well:

    https://neurojustas.com/2018/03/27/tutorial-share-ubuntu-folder-with-windows/

    Personal experience

    I, similar to you, initially tried to run NEURON and other comp-neuro tools under Windows, but over the years have learned that Windows is generally poorly supported within the comp-neuro community. Their software tends to be developed under Ubuntu or MacOS first with occasional testing/support under Win. I even made some software work under Win, but was quickly overwhelmed by problems in other tools. Although I had to go through the hassle of learning Linux, comp-neuro software quality and support for it has been better. I run a Ubuntu VM on Windows to get the best of both worlds.