1

我已经安装了 pyNN 和 nest,但我无法导入它。当我在终端中运行它时,它可以工作,并且程序启动。但是,如果我尝试在 python 中导入:

cd ~
python
import nest

它引发了一个错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/lib/python3.7/site- 
packages/pyNN/nest/__init__.py", line 16, in <module>
    import nest
ModuleNotFoundError: No module named 'nest'

我该如何解决?

编辑:我通过自制软件(在 macOS Mojave 上)安装了 pyNN 和嵌套。

4

1 回答 1

1

一般来说,此类问题可以通过检查 python 的版本和site-packages文件夹的位置来解决:

❯ ipython
Python 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:56:29)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pyNN

In [2]: pyNN
Out[2]: <module 'pyNN' from '/usr/local/anaconda3/envs/vision_snn/lib/python3.9/site-packages/pyNN/__init__.py'>

从您的错误消息来看,您似乎更喜欢使用 anaconda(就像我一样,请参阅上面的代码)。我建议使用 environment.yml文件。一个最小的例子是:

name: nest
channels:
    - conda-forge
dependencies:
   - nest-simulator
   - pip
   - pip:
     - pyNN

然后,您使用以下命令创建虚拟环境:

conda env create -f environment.yml

这对我有用(MacOS 上的 Homebrew):

❯ ipython
Python 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:56:29)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pyNN.nest as sim
[INFO] [2020.11.23 17:6:53 /Users/runner/miniforge3/conda-bld/nest-simulator_1604245451948/work/nestkernel/rng_manager.cpp:217 @ Network::create_rngs_] : Creating default RNGs
[INFO] [2020.11.23 17:6:53 /Users/runner/miniforge3/conda-bld/nest-simulator_1604245451948/work/nestkernel/rng_manager.cpp:260 @ Network::create_grng_] : Creating new default global RNG

              -- N E S T --
  Copyright (C) 2004 The NEST Initiative

 Version: nest-2.20.0
 Built: Nov  1 2020 15:50:27

 This program is provided AS IS and comes with
 NO WARRANTY. See the file LICENSE for details.

 Problems or suggestions?
   Visit https://www.nest-simulator.org

 Type 'nest.help()' to find out more about NEST.

CSAConnector: libneurosim support not available in NEST.
Falling back on PyNN's default CSAConnector.
Please re-compile NEST using --with-libneurosim=PATH
/usr/local/anaconda3/envs/vision_snn/lib/python3.9/site-packages/pyNN/nest/__init__.py:53: UserWarning:Unable to install NEST extensions. Certain models may not be available.

如果您需要更多详细信息,请告诉我。

于 2020-11-23T16:07:49.383 回答