简体   繁体   中英

In jupyter notebook the kernel dies immediately

I just started jupyter notebook and the the kernel just died, the errors were

   [I 18:14:40.316 NotebookApp] Serving notebooks from local directory: C:\Users\brick
[I 18:14:40.316 NotebookApp] 0 active kernels
[I 18:14:40.316 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=da23fdd55f08aadd32334cf72b57034f19637b3016b93520
[I 18:14:40.316 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 18:14:40.332 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=da23fdd55f08aadd32334cf72b57034f19637b3016b93520
[I 18:14:41.346 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[I 18:14:50.920 NotebookApp] Creating new notebook in
[I 18:14:54.477 NotebookApp] Kernel started: c867db6f-d2a4-4ddb-9c25-d811e1f2d532
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 18:14:57.297 NotebookApp] KernelRestarter: restarting kernel (1/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 18:15:00.340 NotebookApp] KernelRestarter: restarting kernel (2/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 18:15:03.359 NotebookApp] KernelRestarter: restarting kernel (3/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[W 18:15:04.589 NotebookApp] Timeout waiting for kernel_info reply from c867db6f-d2a4-4ddb-9c25-d811e1f2d532
[I 18:15:06.378 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel c867db6f-d2a4-4ddb-9c25-d811e1f2d532 restarted
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[W 18:15:09.406 NotebookApp] KernelRestarter: restart failed
[W 18:15:09.406 NotebookApp] Kernel c867db6f-d2a4-4ddb-9c25-d811e1f2d532 died, removing from map.
ERROR:root:kernel c867db6f-d2a4-4ddb-9c25-d811e1f2d532 restarted failed!
[W 18:15:09.468 NotebookApp] Kernel deleted before session
[W 18:15:09.472 NotebookApp] 410 DELETE /api/sessions/4c861646-dd4c-45f9-9863-7ec1f4dec185 (::1) 7.99ms referer=http://localhost:8888/notebooks/Untitled4.ipynb?kernel_name=python3
[I 18:16:54.961 NotebookApp] Saving file at /Untitled4.ipynb
[I 21:29:10.617 NotebookApp] Kernel started: 64d63304-b152-4869-8cff-92612086b891
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 21:29:13.230 NotebookApp] KernelRestarter: restarting kernel (1/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 21:29:16.263 NotebookApp] KernelRestarter: restarting kernel (2/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[I 21:29:19.295 NotebookApp] KernelRestarter: restarting kernel (3/5)
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[W 21:29:21.159 NotebookApp] Timeout waiting for kernel_info reply from 64d63304-b152-4869-8cff-92612086b891
[I 21:29:22.312 NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 64d63304-b152-4869-8cff-92612086b891 restarted
[E 21:29:22.317 NotebookApp] KernelRestarter: restart callback <bound method ZMQChannelsHandler.on_kernel_restarted of ZMQChannelsHandler(64d63304-b152-4869-8cff-92612086b891)> failed
    Traceback (most recent call last):
      File "C:\Users\brick\Miniconda3\lib\site-packages\jupyter_client\restarter.py", line 81, in _fire_callbacks
        callback()
      File "C:\Users\brick\Miniconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 435, in on_kernel_restarted
        self._send_status_message('restarting')
      File "C:\Users\brick\Miniconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 431, in _send_status_message
        self.write_message(json.dumps(msg, default=date_default))
      File "C:\Users\brick\Miniconda3\lib\site-packages\tornado\websocket.py", line 249, in write_message
        raise WebSocketClosedError()
    tornado.websocket.WebSocketClosedError
Could not import runpy module
Traceback (most recent call last):
  File "C:\Users\brick\Miniconda3\lib\runpy.py", line 14, in <module>
    import importlib.machinery # importlib first so we can test #15386 via -m
  File "C:\Users\brick\Miniconda3\lib\importlib\__init__.py", line 57, in <module>
    import types
  File "C:\Users\brick\Miniconda3\lib\types.py", line 171, in <module>
    import functools as _functools
  File "C:\Users\brick\Miniconda3\lib\functools.py", line 21, in <module>
    from collections import namedtuple
ImportError: bad magic number in 'collections': b'\x16\r\r\n'
[W 21:29:25.552 NotebookApp] KernelRestarter: restart failed
[W 21:29:25.552 NotebookApp] Kernel 64d63304-b152-4869-8cff-92612086b891 died, removing from map.
ERROR:root:kernel 64d63304-b152-4869-8cff-92612086b891 restarted failed!
[E 21:29:25.567 NotebookApp] KernelRestarter: dead callback <bound method ZMQChannelsHandler.on_restart_failed of ZMQChannelsHandler(64d63304-b152-4869-8cff-92612086b891)> failed
    Traceback (most recent call last):
      File "C:\Users\brick\Miniconda3\lib\site-packages\jupyter_client\restarter.py", line 81, in _fire_callbacks
        callback()
      File "C:\Users\brick\Miniconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 439, in on_restart_failed
        self._send_status_message('dead')
      File "C:\Users\brick\Miniconda3\lib\site-packages\notebook\services\kernels\handlers.py", line 431, in _send_status_message
        self.write_message(json.dumps(msg, default=date_default))
      File "C:\Users\brick\Miniconda3\lib\site-packages\tornado\websocket.py", line 249, in write_message
        raise WebSocketClosedError()
    tornado.websocket.WebSocketClosedError
[I 23:11:45.347 NotebookApp] Interrupted...
[I 23:11:45.394 NotebookApp] Shutting down kernels

I am using python 3.6.1, and used Miniconda3 to acquire jupyter notebook please help me the kernel also failed to restart. Thanks!

I hope this will finally help me

The "bad magic number" b'\\x16\\r\\r\\n' is used in .pyc files up to Python 3.5.2. Python broke the world when the magic number got updated to \\x17 recently. This may be unrelated to your problem, but my guess is that your interpreter is >= 3.5.3 and your IPython kernel is <= 3.5.2, trying to use the same module-path.

The cause of this error are .pyc files, cached python modules "compiled" by a previous version of Python on your computer, that the interpreter IPython is now using can't unpickle.

The solution is to re-install everything, that is, getting a matching interpreter and IPython. You might get away with simply deleting all .pyc files; they are regenerated automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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