“名称错误:名称'get_ipython'未定义”通过“import ipdb”准备调试会话时 [英] "Name Error: name 'get_ipython' is not defined" while preparing a debugging session via "import ipdb"

查看:5222
本文介绍了“名称错误:名称'get_ipython'未定义”通过“import ipdb”准备调试会话时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to install and use ipdb (IPython-enabled pdb) on Python 3.3.5 32 bit on Win10 using PIP 8.1.2. I've installed via PIP (had to install it seprately) in windows cmd with no errors:

 pip install ipdb

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

I wrote a simple test script expecting to stop in debugger before printing 'test' string, ipdb_test.py:

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

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

When running it from IDLE editor the following exceptions show up:

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'


推荐答案

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

As the issue seemed to be related to IPython, I've checked that the version installed while resolving ipdb dependencies was: "ipython-5.1.0".

问题的WA解决方案是IPython版本4.2.1的后备:

The WA solution for the issue occured to be a fallback to version 4.2.1 of IPython:

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

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

After that ipdb halted on a breakpoint as expected:

$ 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项目团队可能是一个有效的案例,同时我找到了一个运行调试会话的任务已经完成。

It may be a valid case to contact the IPython project team on the issue, meanwhile I find an initial task of running a debug session completed.

这篇关于“名称错误:名称'get_ipython'未定义”通过“import ipdb”准备调试会话时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆