Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pythons Console Module has made it impossible to type the tab key

I started using it on one of my programs a while back. Ever since, whenever I type the tab key on a console (cmd.exe instance) with python running, I get a readline internal error. Full traceback is as follows (note I haven't imported the cmd module in this context or even imported a script using it. I've simply started python, pressed tab and voila an exception):

<pre>
Traceback (most recent call last):
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\rlmain.py", line 571, in readline
    self._readline_from_keyboard()
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\rlmain.py", line 536, in _readline_from_keyboard
    if self._readline_from_keyboard_poll():
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\rlmain.py", line 556, in _readline_from_keyboard_poll
    result = self.mode.process_keyevent(event.keyinfo)
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent
    r = self.process_keyevent_queue[-1](keyinfo)
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent
    r = dispatch_func(keyinfo)
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\modes\basemode.py", line 257, in complete
    completions = self._get_completions()
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions
    r = self.completer(ensure_unicode(text), i)
  File "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\Lib\rlcompleter.py", line 80, in complete
    readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'
</pre>

Before u ask, I installed python to the directory "C:\SP_CI_PROGRAMS\Languages\Python\3.6.1". It's accessible from the path variable. Also any scripts I design I place in a directory u can also access from the path variable (including one using the cmd module for python).

This may not seem like a pressing concern, especially seeing as I can just type 4 spaces instead, however using tabs is something I've become especially accustomed to and the second I type the tab key, anything I've written in a previous block is immediately lost as the traceback is printed. Please, can someone tell me how to fix this.

Edit: This is only within the python interpreter. Typing tab within a running program or something else doesn't pose any problems.

like image 607
Mohsin Kale Avatar asked Jul 09 '18 17:07

Mohsin Kale


4 Answers

Tested solution for Windows 10 (17 January 2020)

  • Copy last traceback file path C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\Lib\rlcompleter.py
  • Open it with any text editor
    • If has VsCode use cmd and copy this
    • code C:\SP_CI_PROGRAMS\Languages\Python\3.6.1\Lib\rlcompleter.py
  • Look the line 80 which traceback tell us
  • Change these line (starts 79) like bellow and It will works
  • There will no error message and unnecessary tab more
...
if _readline_available:                  ## The old one is ##
    if hasattr(readline, 'redisplay'):   # if _readline_available:
        readline.insert_text('\t')       #     readline.insert_text('\t')
        readline.redisplay()             #     readline.redisplay()
    return ''                            # return ''
...

Do not forget to relaunch your python terminal

like image 56
Yedhrab Avatar answered Oct 24 '22 08:10

Yedhrab


Seems to be a continuing issue for Windows machines as seen on Github. A workaround seems to be uninstalling the pyreadline package.

like image 23
Shakes Avatar answered Oct 24 '22 07:10

Shakes


Stop using pyreadline. It's been abandoned. What you're seeing is a known issue, but unless someone takes over pyreadline development, it's unlikely to ever be fixed.

like image 28
user2357112 supports Monica Avatar answered Oct 24 '22 07:10

user2357112 supports Monica


pyreadline can be uninstalled by typing pip uninstall pyreadline in the command prompt. I was experiencing the same issue, but after uninstalling pyreadline, Tab key is working for me.

NOTE: To see the installed packages, type pip list in command prompt.

like image 32
PhysicistSouravDas Avatar answered Oct 24 '22 07:10

PhysicistSouravDas