Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs don't work in python anaconda repl on windows [duplicate]

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 504
Mohsin Kale Avatar asked Jan 20 '26 01:01

Mohsin Kale


2 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 170
Yedhrab Avatar answered Jan 21 '26 14:01

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 37
Shakes Avatar answered Jan 21 '26 13:01

Shakes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!