Python: pyreadline 2.0 bizarre errors on Windows – resolved!

I was fiddling with Python and iPython today on Windows (64-bit installs) and tried the help(‘modules’) command in Idle. Surprisingly, it threw an infinite raft of errors from pyreadline, all of the form:

ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_CONSOLE_SCREEN_BUFFER_INFO instance instead of pointer to CONSOLE_SCREEN_BUFFER_INFO
Readline internal error
Traceback (most recent call last):
 File "C:\Python27\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23
 res = ensure_str(readline_hook(prompt))
 File "C:\Python27\lib\site-packages\pyreadline\rlmain.py", line 569, in readline
 self.readline_setup(prompt)
 File "C:\Python27\lib\site-packages\pyreadline\rlmain.py", line 565, in readline_setup
 self._print_prompt()
 File "C:\Python27\lib\site-packages\pyreadline\rlmain.py", line 466, in _print_prompt
 x, y = c.pos()
 File "C:\Python27\lib\site-packages\pyreadline\console\console.py", line 261, in pos
 self.GetConsoleScreenBufferInfo(self.hout, byref(info))

I took this as a bad sign…

Normally I install Python binaries from LFD’s “Unofficial Windows Binaries for Python Extension Packages” site. I dug around and found there was a very similar bug reported and fixed but never actually merged to the pyreadline master branch – too bad, since it’s pretty much hosed for certain uses without this fix. The binary from LFD (or built as part of a pip install) faithfully contains this bug, so I rebuilt and reinstalled a fixed binary by doing the following:

  • Clone the git repo https://github.com/kivhift/pyreadline
  • Check out the branch argtypes-cleanup
  • Run buildit.bat
    • Not sure what the prerequisites are for this but I happened to have TDM’s gcc and other compilers installed already
  • Install dist/pyreadline-2.0.<yourplatform>.exe
  • Note when installing this, it may present you with multiple Python installs to install for. Since I have Pythons 2.7 (64-bit) and 3.4 (64-bit) I installed it once for each

Once I installed my build of that fix branch, the module worked correctly and stopped spewing errors. Thanks to kivhift for taking the time to track down and fix this vexing bug!

Find this content useful? Share it with your friends!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.