nest / nest-simulator

The NEST simulator
http://www.nest-simulator.org
GNU General Public License v2.0
544 stars 370 forks source link

Python ImportError with pynestkernel #1453

Closed hamanpa closed 4 years ago

hamanpa commented 4 years ago

Hello!

I have tried to install several versions of nest (2.12 - 2.18), but every time I try to import nest in python I get the following ImportError:

Python 2.7.17 (default, Nov  7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pavel/virt_env/mozaik/lib/python2.7/site-packages/PyNEST-nest_2.18.0-py2.7.egg/nest/__init__.py", line 26, in <module>
    from . import ll_api      # noqa
  File "/home/pavel/virt_env/mozaik/lib/python2.7/site-packages/PyNEST-nest_2.18.0-py2.7.egg/nest/ll_api.py", line 72, in <module>
    from . import pynestkernel as kernel      # noqa
ImportError: cannot import name pynestkernel

Inspecting site-packages of virtual environment I found two directories related to nest: PyNEST-nest_2.18.0-py2.7.egg/ nest/

It looks as following:

python2.7/site-packages/
    PyNEST-nest_2.18.0-py2.7.egg/
        EGG-INFO
        nest/
            hl_api.py        __init__.py   ll_api.pyc       tests              voltage_trace.pyc
            hl_api.pyc       __init__.pyc  pynest-init.sli  visualization.py
            import_libs.py   lib           raster_plot.py   visualization.pyc
            import_libs.pyc  ll_api.py     raster_plot.pyc  voltage_trace.py
    nest/
        pynestkernel.so

Any help or suggestion would be appreciated, I'm working with a program built on nest versions 2.12.0 - 2.18.0 so I cannot use newer versions.

Thank you very much, bellow you can find a detailed description of my attempt to install nest.

The detailed description of installation:

1) I create virtual environment using virtualenv, version 20.0.5. Version of python is 2.7.17

2) I download a particular version of nest (tried 2.12.0 - 2.18.0) using $ wget https://github.com/nest/nest-simulator/archive/v2.18.0.tar.gz

3) cmake with following options: cmake -Dwith-mpi=ON -DCMAKE_INSTALL_PREFIX:PATH=$path/to/virtualenv -Dwith-optimize='-O3' ./ 4) make, during this I get following warnings:

[100%] Compiling Cython CXX source for pynestkernel...
warning: pynestkernel.pyx:689:10: Unreachable code
warning: pynestkernel.pyx:689:10: Unreachable code
Scanning dependencies of target pynestkernel
[100%] Building CXX object pynest/CMakeFiles/pynestkernel.dir/pynestkernel.cxx.o
In file included from /usr/include/python2.7/Python.h:83:0,
                 from /home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:4:
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx: In function ‘PyObject* __pyx_pf_12pynestkernel_10NESTEngine_4init(__pyx_obj_12pynestkernel_NESTEngine*, PyObject*, PyObject*)’:
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:1393:27: note: in expansion of macro ‘Py_INCREF’
   #define __Pyx_INCREF(r) Py_INCREF(r)
                           ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:6906:3: note: in expansion of macro ‘__Pyx_INCREF’
   __Pyx_INCREF(Py_True);
   ^~~~~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx: In function ‘PyObject* __pyx_f_12pynestkernel_sli_array_to_object(ArrayDatum*)’:
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:11328:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (__pyx_temp=0; __pyx_temp < __pyx_v_dat->size(); __pyx_temp++) {
                        ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:11355:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
                       ~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/python2.7/Python.h:83:0,
                 from /home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:4:
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx: In function ‘void initpynestkernel()’:
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:1393:27: note: in expansion of macro ‘Py_INCREF’
   #define __Pyx_INCREF(r) Py_INCREF(r)
                           ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:29228:3: note: in expansion of macro ‘__Pyx_INCREF’
   __Pyx_INCREF(((PyObject *)(&PyType_Type)));
   ^~~~~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx: In function ‘PyObject* __Pyx_PyInt_EqObjC(PyObject*, PyObject*, long int, long int)’:
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:27:31: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
                               ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32240:9: note: in expansion of macro ‘Py_RETURN_TRUE’
         Py_RETURN_TRUE;
         ^~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:27:31: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
                               ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32246:21: note: in expansion of macro ‘Py_RETURN_TRUE’
         if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                     ^~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32246:42: note: in expansion of macro ‘Py_RETURN_FALSE’
         if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                                          ^~~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:27:31: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
                               ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32256:28: note: in expansion of macro ‘Py_RETURN_TRUE’
             if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                            ^~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32256:49: note: in expansion of macro ‘Py_RETURN_FALSE’
             if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                                                 ^~~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32259:17: note: in expansion of macro ‘Py_RETURN_FALSE’
                 Py_RETURN_FALSE;
                 ^~~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32264:17: note: in expansion of macro ‘Py_RETURN_FALSE’
                 Py_RETURN_FALSE;
                 ^~~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:27:31: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
                               ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32292:27: note: in expansion of macro ‘Py_RETURN_TRUE’
         if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                           ^~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32292:48: note: in expansion of macro ‘Py_RETURN_FALSE’
         if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                                                ^~~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:27:31: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
                               ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32298:37: note: in expansion of macro ‘Py_RETURN_TRUE’
         if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                                     ^~~~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/usr/include/python2.7/boolobject.h:28:32: note: in expansion of macro ‘Py_INCREF’
 #define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
                                ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:32298:58: note: in expansion of macro ‘Py_RETURN_FALSE’
         if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
                                                          ^~~~~~~~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx: In function ‘PyObject* __Pyx_PyBool_FromLong(long int)’:
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:725:28: note: in expansion of macro ‘Py_INCREF’
 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
                            ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:36527:14: note: in expansion of macro ‘__Pyx_NewRef’
   return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
              ^~~~~~~~~~~~
/usr/include/python2.7/object.h:769:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     ((PyObject*)(op))->ob_refcnt++)
                      ^
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:725:28: note: in expansion of macro ‘Py_INCREF’
 #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
                            ^~~~~~~~~
/home/pavel/projects/Mozaik/nest-simulator-2.18.0/pynest/pynestkernel.cxx:36527:38: note: in expansion of macro ‘__Pyx_NewRef’
   return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
                                      ^~~~~~~~~~~~
[100%] Linking CXX shared module pynestkernel.so
[100%] Built target pynestkernel

5) make install (without any problems)

6) make installcheck - this is successful up to Phase 7:

    Phase 7: Running PyNEST tests.
    ------------------------------

      Nosetests unavailable. Using fallback test harness.
      Fewer tests will be excuted.

    Traceback (most recent call last):
      File "/home/pavel/virt_env/mozaik/share/nest/extras/do_tests.py", line 49, in <module>
        import nest
      File "/home/pavel/virt_env/mozaik/lib/python2.7/site-packages/PyNEST-nest_2.18.0-py2.7.egg/nest/__init__.py", line 26, in <module>
        from . import ll_api      # noqa
      File "/home/pavel/virt_env/mozaik/lib/python2.7/site-packages/PyNEST-nest_2.18.0-py2.7.egg/nest/ll_api.py", line 72, in <module>
        from . import pynestkernel as kernel      # noqa
    ImportError: cannot import name pynestkernel
    cat: pynest_test_numbers.log: No such file or directory
    cat: pynest_test_numbers.log: No such file or directory
    cat: pynest_test_numbers.log: No such file or directory
    cat: pynest_test_numbers.log: No such file or directory

      PyNEST tests:
         Passed:
         Skipped:
         Failed:
    /home/pavel/virt_env/mozaik/share/nest/extras/do_tests.sh: 784: /home/pavel/virt_env/mozaik/share/nest/extras/do_tests.sh: arithmetic expression: expecting primary: " 367 +  "
    CMakeFiles/installcheck.dir/build.make:57: recipe for target 'CMakeFiles/installcheck' failed
    make[3]: *** [CMakeFiles/installcheck] Error 2
    CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/installcheck.dir/all' failed
    make[2]: *** [CMakeFiles/installcheck.dir/all] Error 2
    CMakeFiles/Makefile2:106: recipe for target 'CMakeFiles/installcheck.dir/rule' failed
    make[1]: *** [CMakeFiles/installcheck.dir/rule] Error 2
    Makefile:188: recipe for target 'installcheck' failed
    make: *** [installcheck] Error 2

7) While inspecting site-packages I found the following structure of directories (as mentioned at the beginning):

python2.7/site-packages/
    PyNEST-nest_2.18.0-py2.7.egg/
        EGG-INFO
        nest/
            hl_api.py        __init__.py   ll_api.pyc       tests              voltage_trace.pyc
            hl_api.pyc       __init__.pyc  pynest-init.sli  visualization.py
            import_libs.py   lib           raster_plot.py   visualization.pyc
            import_libs.pyc  ll_api.py     raster_plot.pyc  voltage_trace.py
    nest/
        pynestkernel.so

8) calling nest goes without any error:

$ nest
[INFO] [2020.3.5 10:33:30 /home/pavel/projects/Mozaik/nest-simulator-2.18.0/nestkernel/rng_manager.cpp:217 @ Network::create_rngs_] : Creating default RNGs
[INFO] [2020.3.5 10:33:30 /home/pavel/projects/Mozaik/nest-simulator-2.18.0/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.18.0
 Built: Mar  5 2020 09:47:42

Thank you very much for any help.

terhorstd commented 4 years ago

Dear @AccidentalThought, there seems to be something strange in your python environment. To understand the problem better it would be helpful to have a look at the Configuration Summary at the end of the cmake call. All paths relevant for NEST are shown there.

Two more comments:

gtrensch commented 4 years ago

Closed due to inactivity. Please reopen if problem persists.