"名称错误:姓名' get_ipython'没有定义"通过" import ipdb"准备调试会话时

时间:2016-09-14 18:02:06

标签: python python-3.x ipython ipdb

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

 pip install ipdb

我写了一个简单的测试脚本,期望在打印之前停止在调试器中测试' string, 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'

1 个答案:

答案 0 :(得分:2)

由于问题似乎与IPython有关,我已经检查过在解析ipdb依赖项时安装的版本是:&#34; ipython-5.1.0&#34;。

该问题的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项目团队可能是一个有效的案例,同时我发现完成调试会话的初始任务。