0

我正在尝试使用 PIP 8.1.2 在 Win10 上的 Python 3.3.5 32 位上安装和使用 ipdb(启用 IPython 的 pdb)。我已经在 windows cmd 中通过 PIP 安装(必须单独安装),没有错误:

 pip install ipdb

我写了一个简单的测试脚本,希望在打印“测试”字符串ipdb_test.py之前在调试器中停止:

import ipdb
ipdb.set_trace()
print('test')

从 IDLE 编辑器运行它时,会出现以下异常:

Traceback (most recent call last):
  File "C:\Python33.5-32\lib\site-packages\ipdb\__main__.py", line 44, in <module>
    get_ipython
NameError: name 'get_ipython' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/temp/ipdb_test.py", line 1, in <module>
    import ipdb
  File "C:\Python33.5-32\lib\site-packages\ipdb\__init__.py", line 7, in <module>
    from ipdb.__main__ import set_trace, post_mortem, pm, run             # noqa
  File "C:\Python33.5-32\lib\site-packages\ipdb\__main__.py", line 51, in <module>

  (...)

  File "C:\Python33.5-32\lib\site-packages\prompt_toolkit\terminal\win32_output.py", line 266, in flush
    self.stdout.flush()
AttributeError: 'NoneType' object has no attribute 'flush'
4

1 回答 1

2

由于该问题似乎与 IPython 有关,因此我检查了在解决 ipdb 依赖项时安装的版本是:“ipython-5.1.0”。

该问题的 WA 解决方案恰好是对 IPython 4.2.1 版的回退:

pip install "ipython<5"
    (...)
    Successfully uninstalled ipython-5.1.0
    Successfully installed ipython-4.2.1

之后 ipdb 按预期在断点处停止:

$ python C:\temp\ipdb_test.py
WARNING: Readline services not available or not loaded.
WARNING: Proper color support under MS Windows requires the pyreadline library.
You can find it at:
http://ipython.org/pyreadline.html

Defaulting color scheme to 'NoColor'
> c:\temp\ipdb_test.py(3)<module>()
      1 import ipdb
      2 ipdb.set_trace()
----> 3 print('test')

ipdb>

就这个问题联系 IPython 项目团队可能是一个有效的案例,同时我发现运行调试会话的初始任务已完成。

于 2016-09-14T23:51:22.190 回答