2

After installing the Nest Neural Simulator, I keep getting the following error when trying to run any of the example python files that came in the installation. I've tried re-installing Nest, Python, and using Anaconda, but no go.

Python error:

ImportError: No module named nest

Suggestions?

Robin De Schepper
  • 4,942
  • 4
  • 35
  • 56
alexfigtree
  • 1,516
  • 14
  • 16
  • 2
    possible duplicate of [python says “no module named nest” when it is in the $PATH](http://stackoverflow.com/questions/14065641/python-says-no-module-named-nest-when-it-is-in-the-path) – orvi Aug 16 '15 at 23:50
  • Similar, but this question takes into account changes even to $PATH, including in the bash_profile. ($PATH was changed but “no module named nest”error still occurred.) – alexfigtree Aug 17 '15 at 04:24
  • how do you add your path ? can you add this method on your profile ? – orvi Aug 17 '15 at 07:13
  • Yes, added /opt/nest to bash_profile. Did not help. The answer below did, though. – alexfigtree Aug 17 '15 at 22:48

4 Answers4

2

At https://nest-simulator.org/documentation you now find many different install instructions and how to solve the "ImportError: no module named nest" depends on the way you installed NEST.

System Python

The problem with the nest python module not being found is usually, that NEST is installed for a specific Python version and you can not load it from another. So while many OS still use Python 2.7 you may need to explicitly run

$ python3
>>> import nest

Additionally, if you have multiple Python 3.x versions installed, modules may still be installed for a different version and you have to explicitly start python with python3.6 or python3.8, etc.

Conda package

As @nosratullah-mohammadi already mentioned, if you have a Conda flavour installed, using the pre-built package is a very quick solution. The link in his post is unfortunately broken; this one should work, then go to "Installation" in the side bar.

$ conda create --name nest -c conda-forge python3 nest-simulator
$ conda activate nest
$ python           # this should load the Python from the conda env
>>> import nest    # this loads nest which is installed explicitly for that Python

From Source

For every install from source, be sure to have Python and other prerequisites installed before building NEST. Then you can create your temporary build directory (can be deleted afterwards) and configure with the flags you need.

cd somewhere
mkdir nest-build
cd nest-build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/install/path -Dwith-python=3 .../sources/of/nest-simulator

Replace somewhere, /install/path and .../sources/of/nest-simulator with the paths correct for your setup. (A popular choice when compiling from source in conjunction with Conda environments, for example, is to use -CMAKE_INSTALL_PREFIX=$CONDA_PREFIX, which installs NEST directly into the active environment. Conda is however in no way necessary for NEST.)

Add more -D... flags as you prefer. Possible flags you see with cmake -LA .../sources/of/nest-simulator, as pointed out here. You are probably interested in many of the with-xyz at the end. Check the aforementioned documentation for deatils.

Check that the paths and libraries reported in the Configuration Summary make sense (you may need to scroll up a bit to see). It could for example look something like this:

--------------------------------------------------------------------------------
NEST Configuration Summary
--------------------------------------------------------------------------------

[...]
Python bindings     : Yes (Python 3.6.8: /home/yourname/miniconda3/envs/nest/bin/python3)
       Includes     : /home/yourname/miniconda3/envs/nest/include/python3.6m
       Libraries    : /home/yourname/miniconda3/envs/nest/lib/libpython3.6m.so

Cython bindings     : Yes (Cython 0.27.3: /home/yourname/miniconda3/envs/nest/bin/cython)
[...]
--------------------------------------------------------------------------------

[...]
PyNEST will be installed to:
    /home/yourname/miniconda3/envs/nest/lib/python3.6/site-packages
--------------------------------------------------------------------------------

In this example CMake configured everything for Python3.6 from my conda environment.

If you are satisfied with your settings and all the found Python versions match, run the usual

$ make     # optionally with -j$(nproc)
$ make install
$ make installcheck

In case that works out fine you are done and can delete the build directory to free the space. Congratulations! Also if things get too mixed up and it doesn't seem to do what you expect, it is sometimes useful to delete the build directory and start off clean.

TerhorstD
  • 265
  • 1
  • 2
  • 12
1

NEST now provide the solution to that problem and similar ones, by providing a script which automatically sets the relevant system variables:

If your operating system does not find the nest executable or Python does not find the nest module, your path variables may not be set correctly. This may also be the case if Python cannot load the nest module due to missing or incompatible libraries. In this case, please run

    source </path/to/nest_install_dir>/bin/nest_vars.sh

to set the necessary environment variables. You may want to include this line in your .bashrc file, so that the environment variables are set automatically.

iacob
  • 20,084
  • 6
  • 92
  • 119
Martino
  • 729
  • 6
  • 18
1

there is a new method of installation added to other methods, wich is installing nest with conda package and it's in its beta version. but it works and it's really simple. you can find the installation from here! simply after install mini conda package run your terminal and type this :

conda create --name ENVNAME -c conda-forge nest-simulator python

then type :

conda activate ENVNAME

and you're good to go!

TerhorstD
  • 265
  • 1
  • 2
  • 12
0

Turns out I needed to move the directory where I installed nest (Users/name/opt/nest) into a nest folder in the following directory in anaconda. Specifically, I moved the contents of the folder (from the nest installation):

/Users/name/opt/nest/lib/python2.7/site-packages/nest

Into this one:

/anaconda/lib/python2.7/site-packages/nest

Disclaimer: I could very well run into problems for not having copied all the contents of the Nest installation, but this little hack is helping me run example files now.

alexfigtree
  • 1,516
  • 14
  • 16