nest-simulator icon indicating copy to clipboard operation
nest-simulator copied to clipboard

Error when importing nest in ipython

Open JiaweiShen1116 opened this issue 3 years ago • 16 comments

Hello,

I installed nest via conda, along with ipython in my environment. However, when I open ipython and type "import nest", it reports an error as following:

Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.28.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import nest
<frozen importlib._bootstrap>:228: RuntimeWarning: compiletime version 3.8 of module 'pynestkernel' does not match runtime version 3.9

Oct 10 23:58:31 stop [Error]: 
    No stopped context was found! 


Oct 10 23:58:32 stop [Error]: 
    No stopped context was found! 

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-d0a3dc3bba7c> in <module>
----> 1 import nest

~/opt/miniconda3/envs/NEST/lib/python3.8/site-packages/nest/__init__.py in <module>
     43 _original_module_attrs = globals().copy()
     44 
---> 45 from .ll_api import KernelAttribute  # noqa
     46 import sys                           # noqa
     47 import types                         # noqa

~/opt/miniconda3/envs/NEST/lib/python3.8/site-packages/nest/ll_api.py in <module>
    408 
    409 
--> 410 init(sys.argv)

~/opt/miniconda3/envs/NEST/lib/python3.8/site-packages/nest/ll_api.py in init(argv)
    400                 import keyword
    401                 from .lib.hl_api_models import Models           # noqa
--> 402                 keyword.kwlist += Models()
    403             except ImportError:
    404                 pass

~/opt/miniconda3/envs/NEST/lib/python3.8/site-packages/nest/ll_api.py in stack_checker_func(*args, **kwargs)
    225     def stack_checker_func(*args, **kwargs):
    226         if not get_debug():
--> 227             return f(*args, **kwargs)
    228         else:
    229             sr('count')

~/opt/miniconda3/envs/NEST/lib/python3.8/site-packages/nest/lib/hl_api_models.py in Models(mtype, sel)
     80     if mtype in ("all", "nodes"):
     81         sr("modeldict")
---> 82         models += spp().keys()
     83 
     84     if mtype in ("all", "synapses"):

AttributeError: 'str' object has no attribute 'keys'

I don't know how to fix this issue and it is not listed on the troubleshoot page. Please help. Thank you very much.

JiaweiShen1116 avatar Oct 11 '21 07:10 JiaweiShen1116

@steffengraber, could you have a look here? Seems like the ipython dependency does not catch the python version correctly.

terhorstd avatar Oct 28 '21 10:10 terhorstd

@JiaweiShen1116, which conda package of nest-simulator are you using? (In your environment type conda env export and look for a line like - nest-simulator=2.20.2=py39hadb4b93_0)

How did you create your environment?

terhorstd avatar Oct 28 '21 10:10 terhorstd

Hi! I have a similar issue. Suggestions would be much appreciated. Here's the error message I get, and also the output of conda env export:

Error message:

Python 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nest
<frozen importlib._bootstrap>:228: RuntimeWarning: compiletime version 3.8 of module 'pynestkernel' does not match runtime version 3.9

Oct 29 13:08:39 stop [Error]:
    No stopped context was found!


Oct 29 13:08:39 stop [Error]:
    No stopped context was found!

conda env export output:

name: NEST_env
channels:
  - conda-forge
  - defaults
dependencies:
  - anyio=2.2.0=py39hecd8cb5_1
  - appnope=0.1.2=py39hecd8cb5_1001
  - argon2-cffi=20.1.0=py39h9ed2024_1
  - async_generator=1.10=pyhd3eb1b0_0
  - attrs=21.2.0=pyhd3eb1b0_0
  - babel=2.9.1=pyhd3eb1b0_0
  - backcall=0.2.0=pyhd3eb1b0_0
  - bleach=4.0.0=pyhd3eb1b0_0
  - brotli=1.0.9=hb1e8313_2
  - brotlipy=0.7.0=py39h9ed2024_1003
  - ca-certificates=2021.10.26=hecd8cb5_2
  - certifi=2021.10.8=py39hecd8cb5_0
  - cffi=1.14.6=py39h2125817_0
  - charset-normalizer=2.0.4=pyhd3eb1b0_0
  - cryptography=35.0.0=py39h2fd3fbb_0
  - cycler=0.10.0=py39hecd8cb5_0
  - debugpy=1.4.1=py39h23ab428_0
  - decorator=5.1.0=pyhd3eb1b0_0
  - defusedxml=0.7.1=pyhd3eb1b0_0
  - entrypoints=0.3=py39hecd8cb5_0
  - fonttools=4.25.0=pyhd3eb1b0_0
  - freetype=2.11.0=hd8bbffd_0
  - giflib=5.2.1=haf1e3a3_0
  - gsl=2.7=h93259b0_0
  - idna=3.2=pyhd3eb1b0_0
  - importlib-metadata=4.8.1=py39hecd8cb5_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - ipykernel=6.4.1=py39hecd8cb5_1
  - ipython=7.27.0=py39h01d92e1_0
  - ipython_genutils=0.2.0=pyhd3eb1b0_1
  - jedi=0.18.0=py39hecd8cb5_1
  - jinja2=3.0.1=pyhd3eb1b0_0
  - jpeg=9d=h9ed2024_0
  - json5=0.9.6=pyhd3eb1b0_0
  - jsonschema=3.2.0=pyhd3eb1b0_2
  - jupyter_client=7.0.1=pyhd3eb1b0_0
  - jupyter_core=4.8.1=py39hecd8cb5_0
  - jupyter_server=1.4.1=py39hecd8cb5_0
  - jupyterlab=3.2.1=pyhd8ed1ab_0
  - jupyterlab_pygments=0.1.2=py_0
  - jupyterlab_server=2.8.2=pyhd3eb1b0_0
  - kiwisolver=1.3.1=py39h23ab428_0
  - krb5=1.19.2=hcd88c3b_0
  - lcms2=2.12=hf1fd2bf_0
  - libblas=3.9.0=12_osx64_openblas
  - libcblas=3.9.0=12_osx64_openblas
  - libcbor=0.8.0=he49afe7_0
  - libcxx=12.0.0=h2f01273_0
  - libedit=3.1.20210714=h9ed2024_0
  - libffi=3.3=hb1e8313_2
  - libfido2=1.9.0=h64a5342_1
  - libgfortran=5.0.0=9_3_0_h6c81a4c_23
  - libgfortran5=9.3.0=h6c81a4c_23
  - liblapack=3.9.0=12_osx64_openblas
  - libopenblas=0.3.18=openmp_h3351f45_0
  - libpng=1.6.37=ha441bb4_0
  - libsodium=1.0.18=h1de35cc_0
  - libtiff=4.2.0=h87d7836_0
  - libtool=2.4.6=haf1e3a3_1005
  - libwebp=1.2.0=hacca55c_0
  - libwebp-base=1.2.0=h9ed2024_0
  - libzlib=1.2.11=h9173be1_1013
  - llvm-openmp=12.0.1=hda6cdc1_1
  - lz4-c=1.9.3=h23ab428_1
  - markupsafe=2.0.1=py39h9ed2024_0
  - matplotlib=3.4.3=py39h6e9494a_1
  - matplotlib-base=3.4.3=py39h0a11d32_0
  - matplotlib-inline=0.1.2=pyhd3eb1b0_2
  - mistune=0.8.4=py39h9ed2024_1000
  - mpi=1.0=openmpi
  - mpi4py=3.1.1=py39hc5478b2_0
  - munkres=1.1.4=py_0
  - nbclassic=0.2.6=pyhd3eb1b0_0
  - nbclient=0.5.3=pyhd3eb1b0_0
  - nbconvert=6.1.0=py39hecd8cb5_0
  - nbformat=5.1.3=pyhd3eb1b0_0
  - ncurses=6.2=h0a44026_1
  - nest-asyncio=1.5.1=pyhd3eb1b0_0
  - nest-simulator=3.1=py39haccd9fe_1
  - notebook=6.4.3=py39hecd8cb5_0
  - numpy=1.21.3=py39h7eed0ac_0
  - olefile=0.46=pyhd3eb1b0_0
  - openmpi=4.1.1=hd3cd54c_0
  - openssh=8.8p1=h20b7831_1
  - openssl=1.1.1l=h9ed2024_0
  - packaging=21.0=pyhd3eb1b0_0
  - pandas=1.2.4=py39h23ab428_0
  - pandocfilters=1.4.3=py39hecd8cb5_1
  - parso=0.8.2=pyhd3eb1b0_0
  - patsy=0.5.2=py39hecd8cb5_0
  - pexpect=4.8.0=pyhd3eb1b0_3
  - pickleshare=0.7.5=pyhd3eb1b0_1003
  - pillow=8.4.0=py39h98e4679_0
  - pip=21.2.4=py39hecd8cb5_0
  - prometheus_client=0.11.0=pyhd3eb1b0_0
  - prompt-toolkit=3.0.20=pyhd3eb1b0_0
  - ptyprocess=0.7.0=pyhd3eb1b0_2
  - pycparser=2.20=py_2
  - pygments=2.10.0=pyhd3eb1b0_0
  - pyopenssl=21.0.0=pyhd3eb1b0_1
  - pyparsing=2.4.7=pyhd3eb1b0_0
  - pyrsistent=0.18.0=py39h9ed2024_0
  - pysocks=1.7.1=py39hecd8cb5_0
  - python=3.9.7=h88f2d9e_1
  - python-dateutil=2.8.2=pyhd3eb1b0_0
  - python.app=1.3=py39h89e85a6_5
  - python_abi=3.9=2_cp39
  - pytz=2021.3=pyhd3eb1b0_0
  - pyzmq=22.2.1=py39h23ab428_1
  - readline=8.1=h9ed2024_0
  - requests=2.26.0=pyhd3eb1b0_0
  - scipy=1.7.1=py39h056f1c0_0
  - seaborn=0.11.2=hd8ed1ab_0
  - seaborn-base=0.11.2=pyhd8ed1ab_0
  - send2trash=1.8.0=pyhd3eb1b0_1
  - setuptools=58.0.4=py39hecd8cb5_0
  - six=1.16.0=pyhd3eb1b0_0
  - sniffio=1.2.0=py39hecd8cb5_1
  - sqlite=3.36.0=hce871da_0
  - statsmodels=0.13.0=py39hca72f7f_0
  - terminado=0.9.4=py39hecd8cb5_0
  - testpath=0.5.0=pyhd3eb1b0_0
  - tk=8.6.11=h7bc2e8c_0
  - tornado=6.1=py39h9ed2024_0
  - traitlets=5.1.0=pyhd3eb1b0_0
  - tzdata=2021e=hda174b7_0
  - urllib3=1.26.7=pyhd3eb1b0_0
  - wcwidth=0.2.5=pyhd3eb1b0_0
  - webencodings=0.5.1=py39hecd8cb5_1
  - wheel=0.37.0=pyhd3eb1b0_1
  - xz=5.2.5=h1de35cc_0
  - zeromq=4.3.4=h23ab428_0
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.11=h9173be1_1013
  - zstd=1.4.9=h322a384_0
prefix: /Users/admin/anaconda3/envs/NEST_env

roopa-pai avatar Oct 29 '21 11:10 roopa-pai

Issue automatically marked stale!

github-actions[bot] avatar Jan 08 '22 08:01 github-actions[bot]

Has anyone managed to resolve the issue?

SimonSenn avatar May 12 '22 12:05 SimonSenn

In both cases reported above, there seems to be a mix-up between running a Python 3.9 interpreter and a NEST module built for Python 3.8. Conda should handle this properly in its dependency tracking.

Currently, NEST 3.3 is available on conda-forge in versions build for Python 3.8, 3.9 and 3.10. Could you please try again in a new, clean conda environment and report if this solves the problem?

heplesser avatar May 12 '22 12:05 heplesser

Thanks for the answer. Indeed, I have tried multiple times to install nest-simulator in a new and clean environment (nest_project2) but I always receive an import error as shown here:

Traceback (most recent call last): File "/Users/Simon/PycharmProjects/nest_project2/Try_5.py", line 1, in import nest File "/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/init.py", line 53, in from .ll_api import KernelAttribute # noqa File "/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/ll_api.py", line 51, in from . import pynestkernel as kernel # noqa ImportError: dlopen(/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/pynestkernel.so, 0x000A): Library not loaded: @rpath/libgsl.25.dylib Referenced from: /Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/libmodels.dylib Reason: tried: '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/bin/../lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/bin/../lib/libgsl.25.dylib' (no such file), '/usr/local/lib/libgsl.25.dylib' (no such file), '/usr/lib/libgsl.25.dylib' (no such file)Library not loaded: @rpath/libgsl.25.dylib Referenced from: /Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/libsli.dylib Reason: tried: '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/nest/../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../lib/nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../nest/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/python3.10/site-packages/nest/../../../libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/bin/../lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/lib/libgsl.25.dylib' (no such file), '/Users/Simon/opt/anaconda3/envs/nest_project2/bin/../lib/libgsl.25.dylib' (no such file), '/usr/local/lib/libgsl.25.dylib' (no such file), '/usr/lib/libgsl.25.dylib' (no such file)

Process finished with exit code 1

I figured that it is looking for the gsl package version 2.5. However, in the newest available nest library, gsl 2.7 is installed. I finally managed to import nest successfully by installing an old version (namely 2.18.0) in a new environment (nest_project). However, when I want to run a simple single-neuron simulation on PyCharm, it somehow does not seem to find the models.

May 12 15:12:28 stop [Error]: No stopped context was found!

Traceback (most recent call last): File "/Users/Simon/PycharmProjects/nest_project/Try_3.py", line 4, in neuron = nest.Create("iaf_psc_alpha") File "/Users/Simon/opt/anaconda3/envs/nest_project/lib/python3.8/site-packages/nest/ll_api.py", line 246, in stack_checker_func return f(*args, **kwargs) File "/Users/Simon/opt/anaconda3/envs/nest_project/lib/python3.8/site-packages/nest/lib/hl_api_nodes.py", line 83, in Create gids = tuple(range(last_gid - n + 1, last_gid + 1)) TypeError: unsupported operand type(s) for -: 'str' and 'int'

Process finished with exit code 1

Thanks in advance for any help.

SimonSenn avatar May 12 '22 13:05 SimonSenn

@SimonSenn Based on the log, I assume that you are working on a Mac. Does you machine have AppleSilicon or an Intel CPU?

heplesser avatar May 12 '22 13:05 heplesser

Correct. My Mac has an Intel CPU.

SimonSenn avatar May 12 '22 13:05 SimonSenn

I just tested on my Mac with macOS 12.3, Intel CPU. I have version 4.12.0 with Python 3.8 in the base conda environment (miniconda, not full anaconda). I then executed (in base)

conda create --name nest_test -c conda-forge nest-simulator ipython jupyterlab

Conda then created an environment with Python 3.10 and GSL 2.7. After activating it, running nest directly and importing nest from python and ipython worked for me. My paths with nest_test activated look like this

PATH: /Users/plesser/opt/miniconda3/envs/nest_test/bin:/Users/plesser/bin:/Users/plesser/opt/miniconda3/envs/nest_test/bin:/Users/plesser/opt/miniconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin
PYTHONPATH: /Users/plesser/opt/miniconda3/envs/nest_test/lib/python3.10/site-packages

Could you compare with your setup?

heplesser avatar May 12 '22 14:05 heplesser

Thank you very much! It did not work in the beginning. Then, I uninstalled anaconda and all connected files and reinstalled miniconda. I then followed your steps and it works now. I don't know if it was a mismatch between different versions or if my paths were not set correctly. Anyway, thanks for your help!

SimonSenn avatar May 14 '22 14:05 SimonSenn

Sorry for bothering again. I encountered another problem it seems. I can import nest and all but when I try to apply commands like nest.Create() or nest.Connect(), PyCharm gives me a warning saying:

Cannot find reference 'Create' in 'init.py'

Does anyone have a solution?

SimonSenn avatar May 15 '22 16:05 SimonSenn

NEST imports its components in an indirect way. This may confuse PyCharms code completion scheme and other features.

  • In PyCharm, do you get the warning when running the code or is it a warning from the PyCharm editor? Could you maybe post a screen shot?
  • Could you test in a python or ipython shell that runs in the terminal, outside PyCharm?

heplesser avatar May 18 '22 06:05 heplesser

@SimonSenn Do you still have the problem in PyCharm?

steffengraber avatar Jul 01 '22 08:07 steffengraber

@roopa-pai , @JiaweiShen1116 Are your difficulties with the import of NEST solved with the advice given so far?

steffengraber avatar Jul 01 '22 08:07 steffengraber

Issue automatically marked stale!

github-actions[bot] avatar Aug 31 '22 08:08 github-actions[bot]

Closed. Seems to be solved.

steffengraber avatar Oct 18 '22 10:10 steffengraber