Python 击中选项卡失败并显示 Python AttributeError:模块“readline”没有属性“redisplay”

wkz*_*zhu 7 python readline python-3.x anaconda

在 Windows 上使用 Python 3.7.3 (Anaconda),点击 tab 会导致以下回溯:

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'
Run Code Online (Sandbox Code Playgroud)

环境细节:

  • 视窗 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.
Run Code Online (Sandbox Code Playgroud)

尝试这样做也没有帮助:无法在 Windows 上使用 pip 安装“pyreadline”

Mig*_*rez 9

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
Run Code Online (Sandbox Code Playgroud)