简体   繁体   English

Nest 模拟器:python 说“没有名为 nest 的模块”

[英]Nest simulator: python says “no module named nest”

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.安装 Nest Neural Simulator 后,在尝试运行安装中提供的任何示例 python 文件时,我不断收到以下错误。 I've tried re-installing Nest, Python, and using Anaconda, but no go.我试过重新安装 Nest、Python 和使用 Anaconda,但没有成功。

Python error:蟒蛇错误:

ImportError: No module named nest导入错误:没有名为 nest 的模块

Suggestions?建议?

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.https://nest-simulator.org/documentation,您现在可以找到许多不同的安装说明,以及如何解决“ImportError: no module named nest”取决于您安装 NEST 的方式。

System Python系统 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.找不到nest python 模块的问题通常是,NEST 是为特定的 Python 版本安装的,您无法从另一个版本加载它。 So while many OS still use Python 2.7 you may need to explicitly run因此,虽然许多操作系统仍然使用 Python 2.7,但您可能需要显式运行

$ 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.此外,如果您安装了多个 Python 3.x 版本,则可能仍会为不同版本安装模块,并且您必须使用python3.6python3.8等显式启动 python。

Conda package康达包

As @nosratullah-mohammadi already mentioned, if you have a Conda flavour installed, using the pre-built package is a very quick solution.正如@nosratullah-mohammadi 已经提到的,如果您安装了 Conda 风格,使用预构建包是一个非常快速的解决方案。 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.对于每次从源代码安装,请确保构建 NEST之前安装 Python 和其他先决条件。 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.用适合您的设置的路径替换somewhere/install/path.../sources/of/nest-simulator (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.) (例如,从源代码与 Conda 环境一起编译时,一个流行的选择是使用-CMAKE_INSTALL_PREFIX=$CONDA_PREFIX ,它将 NEST 直接安装到活动环境中。然而,NEST 绝不需要 Conda。)

Add more -D... flags as you prefer.根据需要添加更多-D...标志。 Possible flags you see with cmake -LA .../sources/of/nest-simulator , as pointed out here .您在cmake -LA .../sources/of/nest-simulator看到的可能标志,如这里所指出的。 You are probably interested in many of the with-xyz at the end.您可能对末尾的许多with-xyz感兴趣。 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).检查Configuration Summary报告的路径和库是否有意义(您可能需要向上滚动一点才能看到)。 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.在此示例中,CMake 为我的 conda 环境中的 Python3.6 配置了所有内容。

If you are satisfied with your settings and all the found Python versions match, run the usual如果您对您的设置感到满意并且所有找到的 Python 版本都匹配,请运行通常的

$ 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.此外,如果事情变得过于混乱并且它似乎没有按照您的预期执行,有时删除构建目录并从干净开始是很有用的。

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.有一种新的安装方法添加到其他方法中,即使用 conda 包安装 nest 并且它处于 beta 版本。 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 :只需在安装 mini conda 包后运行您的终端并输入:

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

then type :然后输入:

conda activate ENVNAME

and you're good to go!一切顺利!

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.原来我需要将安装 nest 的目录(用户/名称/opt/nest)移动到 anaconda 中以下目录中的 nest 文件夹中。 Specifically, I moved the contents of the folder (from the nest installation):具体来说,我移动了文件夹的内容(从巢安装):

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

Into this one:进入这个:

/anaconda/lib/python2.7/site-packages/nest /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.免责声明:我很可能会因为没有复制 Nest 安装的所有内容而遇到问题,但是这个小技巧现在正在帮助我运行示例文件。

NEST now provide the solution to that problem and similar ones, by providing a script which automatically sets the relevant system variables: NEST 现在通过提供自动设置相关系统变量的脚本来提供该问题和类似问题的解决方案:

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.如果您的操作系统未找到 nest 可执行文件或 Python 未找到 nest 模块,则您的路径变量可能未正确设置。 This may also be the case if Python cannot load the nest module due to missing or incompatible libraries.如果 Python 由于缺少或不兼容的库而无法加载嵌套模块,也可能是这种情况。 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.您可能希望在 .bashrc 文件中包含这一行,以便自动设置环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM