欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spyder报错:IPython console无法启用,报错An error ocurred while starting the kernel

程序员文章站 2022-05-27 23:15:50
...

Spyder报错:IPython console无法启用

遇到问题

  1. 我在win7(64bit) 安装了最新的annaconda,安装启用了默认环境spyder3.3.2后遇到了如下问题:
  	
File "E:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 528, in get
  value = obj._trait_values[self.name]
KeyError: 'context'

Traceback (most recent call last):
File "E:\Anaconda3\lib\site-packages\qtconsole\manager.py", line 27, in poll
  super(QtKernelRestarter, self).poll()
File "E:\Anaconda3\lib\site-packages\jupyter_client\restarter.py", line 113, in poll
  self.kernel_manager.restart_kernel(now=True, newports=newports)
File "E:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 368, in restart_kernel
  self.start_kernel(**self._launch_args)
File "E:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 261, in start_kernel
  self._connect_control_socket()
File "E:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 210, in _connect_control_socket
  self._control_socket = self.connect_control()
File "E:\Anaconda3\lib\site-packages\jupyter_client\connect.py", line 571, in connect_control
  return self._create_connected_socket('control', identity=identity)
File "E:\Anaconda3\lib\site-packages\jupyter_client\connect.py", line 543, in _create_connected_socket
  sock = self.context.socket(socket_type)
File "E:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 556, in __get__
  return self.get(obj, cls)
File "E:\Anaconda3\lib\site-packages\traitlets\traitlets.py", line 535, in get
  value = self._validate(obj, dynamic_default())
File "E:\Anaconda3\lib\site-packages\jupyter_client\manager.py", line 42, in _context_default
  return zmq.Context.instance()
File "E:\Anaconda3\lib\site-packages\zmq\sugar\context.py", line 108, in instance
  cls._instance = cls(io_threads=io_threads)
File "zmq/backend/cython/context.pyx", line 49, in zmq.backend.cython.context.Context.__cinit__
zmq.error.ZMQError: Unknown error
Traceback (most recent call last):
  1. 解决上述问题后,我新建了一个包含opencv的新环境,并安装启用了spyder3.3.3后又遇到了如下问题:
Traceback (most recent call last):
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\traitlets\traitlets.py", line 528, in get
value = obj._trait_values[self.name]
KeyError: 'context'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\spyder\plugins\ipythonconsole.py", line 1554, in create_kernel_manager_and_kernel_client
kernel_manager.start_kernel(stderr=stderr_handle)
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\jupyter_client\manager.py", line 261, in start_kernel
self._connect_control_socket()
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\jupyter_client\manager.py", line 210, in _connect_control_socket
self._control_socket = self.connect_control()
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\jupyter_client\connect.py", line 571, in connect_control
return self._create_connected_socket('control', identity=identity)
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\jupyter_client\connect.py", line 543, in _create_connected_socket
sock = self.context.socket(socket_type)
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\traitlets\traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\traitlets\traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\jupyter_client\manager.py", line 42, in _context_default
return zmq.Context.instance()
File "E:\Anaconda3\envs\CvDlib\lib\site‑packages\zmq\sugar\context.py", line 108, in instance
cls._instance = cls(io_threads=io_threads)
File "zmq/backend/cython/context.pyx", line 49, in zmq.backend.cython.context.Context.__cinit__
zmq.error.ZMQError: Bad address

探寻问题的原因

我们使用pyCharm启动,会产生如下提示:

Cannot start internal HTTP server. Git integration, JavaScript debugger and LiveEdit may operate with errors. Please check your firewall settings and restart PyCharm

感谢flyfish1986的答案,错误原因是防火墙。

PS:问题2产生的原因是新加了opencv库(或者说是附加库),导致windows防火墙对程序通讯的阻碍。

解决方法

方法一:

windows防火墙允许以下程序
E:\Anaconda3\pythonw.exe
E:\Anaconda3\pytho.exe
通过防火墙,spyder3.3.2中的IPython即可运行成功!!!

方法二

由于安装了其他库,导致问题2产生,所以关闭了Windows防火墙,该问题消失。
spyder3.3.3中的IPython也可运行成功!!!

相关标签: spyder IPython