我已经安装了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'
我该如何解决?
编辑:我安装了pyNN并通过自制软件(在macOS Mojave上)嵌套。
答案 0 :(得分:0)
通常,可以通过检查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.
如果需要更多详细信息,请告诉我。