问题概述
使用Ipython时,通过Tab键索引包名之类的提示报错,错误详情:
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
Unhandled exception in event loop:
File "e:\python3_7\lib\site-packages\prompt_toolkit\eventloop\coroutine.py", line 92, in step_next
new_f = coroutine.throw(exc)
File "e:\python3_7\lib\site-packages\prompt_toolkit\buffer.py", line 1654, in new_coroutine
yield From(coroutine(*a, **kw))
File "e:\python3_7\lib\site-packages\prompt_toolkit\eventloop\coroutine.py", line 92, in step_next
new_f = coroutine.throw(exc)
File "e:\python3_7\lib\site-packages\prompt_toolkit\buffer.py", line 1506, in async_completer
cancel=lambda: not proceed()))
File "e:\python3_7\lib\site-packages\prompt_toolkit\eventloop\coroutine.py", line 88, in step_next
new_f = coroutine.send(None)
File "e:\python3_7\lib\site-packages\prompt_toolkit\eventloop\async_generator.py", line 117, in consume_async_generator
item = iterator.send(send)
File "e:\python3_7\lib\site-packages\prompt_toolkit\completion\base.py", line 176, in get_completions_async
for item in self.get_completions(document, complete_event):
File "e:\python3_7\lib\site-packages\IPython\terminal\ptutils.py", line 116, in get_completions
exc_type, exc_value, exc_tb = sys.exc_info()
Exception name 'sys' is not defined
Press ENTER to continue...
环境
- Python == 3.8
- IPython == 7.19.0
- jedi == 0.18.0
问题详情
以导入docker包为例,正常情况下IPython具备Tab键备选补全代码功能
但在上述环境中发现只要使用Tab键补全就会触发IPython崩溃问题。网上搜索了好久才找到解决方法,这里做个总结:
方法1
降低IPython版本到7.1.1(含以下)
pip install --upgrade ipython==7.1.1
方法2
降低jedi版本
pip3 install --upgrade 'jedi<0.18.0'
引用: https://github.com/ipython/ipython/issues/12745