在jupyter笔记本中,内核会立即死掉

时间:2017-07-09 14:54:22

标签: python jupyter-notebook

我刚开始jupyter笔记本而内核刚刚死了,错误是

   [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

我正在使用python 3.6.1,并使用Miniconda3获取jupyter笔记本请帮我内核也无法重启。 谢谢!

我希望这最终会帮助我

1 个答案:

答案 0 :(得分:0)

“魔法数字”b'\x16\r\r\n'用于{3.5}中的.pyc文件。神奇数字最近更新为\x17时的Python broke the world。这可能与您的问题无关,但我的猜测是您的解释器是&gt; = 3.5.3并且您的IPython内核是&lt; = 3.5.2,尝试使用相同的模块路径。

此错误的原因是.pyc文件,缓存的python模块由计算机上以前版本的Python“编译”,解释器IPython现在使用的不能解开。

解决方案是重新安装所有内容,即获得匹配的解释器和IPython。您可以简单地删除所有.pyc个文件;它们会自动重生。