winpython / winpython

A free Python-distribution for Windows platform, including prebuilt packages for Scientific Python.
https://winpython.github.io/
MIT License
1.8k stars 300 forks source link

pyreadline workaround for... don't remember what #544

Open stonebig opened 7 years ago

stonebig commented 7 years ago

for cvxpy ?

https://github.com/ankostis/pyreadline/tree/redisplay

stonebig commented 7 years ago

done/ready, if I need it somewhere

ankostis commented 7 years ago

Just to remind that without that branch (actually PR pyreadline/pyreadline#56), pressing [Tab] in python interpreter raises the error described in pyreadline/pyreadline#49:

  File "C:\Users\dbrattli\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions
    r = self.completer(ensure_unicode(text), i)
  File "C:\Users\dbrattli\AppData\Local\Programs\Python\Python35-32\lib\rlcompleter.py", line 80, in complete
    readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'

And readline gets installed because of dill (uqfoundation/dill#181).

stonebig commented 7 years ago

in theory @ankostis , I should have picked your branch in current beta

ankostis commented 7 years ago

...but in practice?

stonebig commented 7 years ago

... in practice, I didn't have much time last month to check anything but new spyder features and jupyterlab-0.26 incompatiblities. maybe someone can confirm cvxpy works well on latest beta.

ankostis commented 7 years ago

The important thing is for the next WinPython to use this branch, or else python interpreter is broken(!), as explained in the issues linked above.

stonebig commented 7 years ago

how I get pyreadline in the interpreter loop is a bit obscure to me, please explain me step by step, so I will check if it blows up

ankostis commented 7 years ago

I have no knowledge of pyreadline - I produced the fix based on other PRs and some superificial study to fix the remaining bugs.

To reproduce the problems, just pip install pyreadline and then lanuch python; you should received:

@cygwin:~$pip install pyreadline
Collecting pyreadline
Installing collected packages: pyreadline
Successfully installed pyreadline-2.1
@cygwin:~$python
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site.py", line 418, in register_readline
    readline.read_history_file(history)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
    self.mode._history.read_history_file(filename)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
    for line in open(filename, 'r'):
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 2581: character maps to <undefined>
>>>

Pressing [Tab] you will receive:

>>> Readline internal error
Traceback (most recent call last):
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\rlmain.py", line 571, in readline
    self._readline_from_keyboard()
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\rlmain.py", line 536, in _readline_from_keyboard
    if self._readline_from_keyboard_poll():
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\rlmain.py", line 556, in _readline_from_keyboard_poll
    result = self.mode.process_keyevent(event.keyinfo)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent
    r = self.process_keyevent_queue[-1](keyinfo)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent
    r = dispatch_func(keyinfo)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\modes\basemode.py", line 257, in complete
    completions = self._get_completions()
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions
    r = self.completer(ensure_unicode(text), i)
  File "D:\Apps\WinPython-64bit-3.6.1.0Qt5\python-3.6.1.amd64\lib\rlcompleter.py", line 80, in complete
    readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'
>>>
TylerGubala commented 6 years ago

I continue to have this issue...? Possibly something that needs to be looked into again?

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32

>>> Readline internal error
Traceback (most recent call last):
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
    res = ensure_str(readline_hook(prompt))
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\rlmain.py", line 571, in readline
    self._readline_from_keyboard()
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\rlmain.py", line 536, in _readline_from_keyboard
    if self._readline_from_keyboard_poll():
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\rlmain.py", line 556, in _readline_from_keyboard_poll
    result = self.mode.process_keyevent(event.keyinfo)
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent
    r = self.process_keyevent_queue[-1](keyinfo)
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent
    r = dispatch_func(keyinfo)
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\modes\basemode.py", line 257, in complete
    completions = self._get_completions()
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions
    r = self.completer(ensure_unicode(text), i)
  File "C:\Users\TGubs\AppData\Local\Programs\Python\Python36\lib\rlcompleter.py", line 80, in complete
    readline.redisplay()
AttributeError: module 'readline' has no attribute 'redisplay'
Zaksh commented 6 years ago

I am also having the same issue on

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32.

When I press TAB I get the following error

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

I was able to remedy this by uninstalling Pyreadline which was temporarily satisfactory for me.

I tried installing a new version of python and it still gave me the same error.

I think pyreadline's presence in site-packages was the issue

stonebig commented 6 years ago

so I may remove it. it's the last legacy of binary packages, and it's more an annoyance than anything.

deduble commented 6 years ago

I have no idea why was this happening? Anyone has an idea was main python was creating these errors and not ipython kernal, with pyreadline and why did I suddenly start to have it? Again removing pyreadline helped me but still...