Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python hitting tab fails with Python AttributeError: module 'readline' has no attribute 'redisplay'

Using Python 3.7.3 (Anaconda) on Windows, hitting tab results in the following traceback:

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'

Environment details:

  • Windows 10 64-bit
  • Python 3.7.3, Anaconda distribution
  • pyreadline == 2.1
  • Tab key works fine in IPython

I am aware pyreadline is likely causing the issue. Tab not working in python 3.6, working in 3.5, 3.6 32 bit version on Windows suggests uninstalling pyreadline. However, when I try pip uninstall pyreadline I get this error:

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.

Trying this also did not help: Unable to install 'pyreadline' using pip on Windows

like image 597
wkzhu Avatar asked Jul 01 '19 15:07

wkzhu


1 Answers

The Anaconda module readline is different from the standard Python readline which does have the method redisplay. The workaround I found to make this work was disabling the autocomplete. To archive that you need to set as True the attribute disable_readline in the file rlmain.py line 58.

..\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
like image 111
Miguel A. Sanchez-Perez Avatar answered Oct 19 '22 15:10

Miguel A. Sanchez-Perez