Python命中选项卡失败并显示Python AttributeError:模块“ readline”没有属性“ redisplay”
在Windows上使用Python 3.7.3(Anaconda),点击选项卡将导致以下回溯:
Readline internal error
Traceback (most recent call last):
File "C:\...\anaconda3\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
res = ensure_str(readline_hook(prompt))
File "C:\...\anaconda3\lib\site-packages\pyreadline\rlmain.py", line 571, in readline
self._readline_from_keyboard()
File "C:\...\anaconda3\lib\site-packages\pyreadline\rlmain.py", line 536, in _readline_from_keyboard
if self._readline_from_keyboard_poll():
File "C:\...\anaconda3\lib\site-packages\pyreadline\rlmain.py", line 556, in _readline_from_keyboard_poll
result = self.mode.process_keyevent(event.keyinfo)
File "C:\...\anaconda3\lib\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent
r = self.process_keyevent_queue[-1](keyinfo)
File "C:\...\anaconda3\lib\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent
r = dispatch_func(keyinfo)
File "C:\...\anaconda3\lib\site-packages\pyreadline\modes\basemode.py", line 257, in complete
completions = self._get_completions()
File "C:\...\anaconda3\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions
r = self.completer(ensure_unicode(text), i)
File "C:\...\anaconda3\lib\rlcompleter.py", line 80, in complete
readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'
环境详细信息:
Windows 10 64位
Python 3.7.3,Anaconda发行版
pyreadline == 2.1
Tab键在IPython中可以正常工作
我知道pyreadline可能是造成此问题的原因。Tab在python 3.6上不起作用,在Windows上的 3.5,3.6 32位版本上工作,建议卸载pyreadline。但是,当我尝试pip uninstall pyreadline此错误时:
Cannot uninstall 'pyreadline'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
尝试此操作也无济于事:无法在Windows上使用pip安装“ pyreadline”
解决方案
Anaconda模块的readline与具有重新显示方法的标准Python readline不同。我发现可以解决此问题的解决方法是禁用自动完成功能。要存档,您需要将rlmain.py文件第58行中的属性disable_readline设置为True 。
… \ Anaconda3 \ Lib \ site-packages \ pyreadline \ rlmain.py
class BaseReadline(object):
def __init__(self):
self.allow_ctrl_c = False
self.ctrl_c_tap_time_interval = 0.3
self.debug = False
self.bell_style = 'none'
self.mark = -1
self.console=MockConsole()
self.disable_readline = True # Old value: False