Spyder IDE 无法在 Windows 10 和 Python 3.8 上启动

Spyder IDE fails to start on Windows 10 with Python 3.8

注意:此问题已在 Spyder 4.1.3 中修复!


(原始问题)在 Windows 上检查 Python 3.8 (x64) 10,我在尝试设置 Spyder 时遇到了麻烦。注意:在干净的 Windows-10 系统上重新安装 Python 可重现该问题。然而,在 Linux 上没有这样的问题(在 debian / Mint19.x 上测试)。

起初,通过 pip install spyder 安装时一切都很顺利。


错误 #1: pywin32

启动Spyder后,在IPython控制台显示window:

Traceback (most recent call last):
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\spyder\plugins\ipythonconsole.py", line 1572, in create_kernel_manager_and_kernel_client
kernel_manager.start_kernel(stderr=stderr_handle)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\manager.py", line 240, in start_kernel
self.write_connection_file()
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 470, in write_connection_file
self.connection_file, cfg = write_connection_file(self.connection_file,
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_client\connect.py", line 141, in write_connection_file
with secure_write(fname) as f:
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 424, in secure_write
win32_restrict_file_to_user(fname)
File "c:\users\USERNAME\appdata\local\programs\python\python38\lib\site‑packages\jupyter_core\paths.py", line 359, in win32_restrict_file_to_user
import win32api
ImportError: DLL load failed while importing win32api: Das angegebene Modul wurde nicht gefunden.

我能够通过脚本文件夹中的 运行 pywin32_postinstall.py -install 修复导入错误(从具有提升权限的 cmd 提示)。将 pythoncom38.dllpywintypes38.dll\Lib\site-packages\pywin32_system32 复制到 \windows\system32,另请参阅下面的 here - however, I'd suggest to not modify system folders and use the option I put in


错误#2: tornado

但是,现在 Spyder 只是在加载屏幕上冻结(显示徽标,说 "initializing main window" 之类的话)!

https://github.com/spyder-ide/spyder.git 克隆 Spyder 的开发版本并通过 python bootstrap.py --debug 运行 它揭示了冻结的原因:

2019-11-03 17:39:53,261 [ERROR] [tornado.application] -> Exception in callback functools.partial(<function ThreadedZMQSocketChannel.__init__.<locals>.setup_stream at 0x0000015E00B758B0>)
Traceback (most recent call last):
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\jupyter_client\threaded.py", line 48, in setup_stream
    self.stream = zmqstream.ZMQStream(self.socket, self.ioloop)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 127, in __init__
    self._init_io_state()
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\zmq\eventloop\zmqstream.py", line 546, in _init_io_state
    self.io_loop.add_handler(self.socket, self._handle_events, self.io_loop.READ)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py", line 99, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

...所以看来 Python 3.8 版本 pywin32 导致的导入错误只是一个问题。还有一个与 tornado IO(网络服务器)相关的问题,请参阅 here / here

last checked with Python 3.8.2 (AMD64), Spyder 4.1.1. Please note that I am not using Anaconda. Use either conda or pip, not both.

Spyder 4.1.3更新:问题已修复!

(在 Python 3.8.3rc1、tornado 6.0.4 上测试)

如果你来到这里仍然遇到类似的 Spyder 启动问题:我建议首先尝试 升级到 Spyder 版本 >= 4.1.3 .


此答案的旧版本

解决方法,龙卷风问题:

修改文件...\Python38...\Lib\site-packages\tornado\platform\asyncio.py; 添加

import sys
if sys.platform == 'win32':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

在其他导入语句之后。资料来源: and also linked here. If I get this post 在 tornado 回购权上,这可能是一个非常永久的解决方法。


如果还需要 - 解决方法,pywin32 问题:

修改文件...\Python38\Lib\site-packages\jupyter_core\path.py; 添加一行

import pywintypes

before import win32api in line 359. 此修改基于 post.