xonsh_kernel icon indicating copy to clipboard operation
xonsh_kernel copied to clipboard

Unable to use IPython.display - '_io.StringIO' object has no attribute 'softspace'

Open mjbright opened this issue 8 years ago • 4 comments

I tried to use the IPython display functionality as below:

from IPython.display import display,HTML display(HTML('<h4>Here is an H4 header</h4>'))

but I get the following error (on Ubuntu 16.04 and on Windows7, using Anaconda Python).

AttributeError: '_io.StringIO' object has no attribute 'softspace'

Below is my config (on Ubuntu):

mjb@NUC ~ $ xonfig
+------------------+----------+
| xonsh            | 0.3.4    |
| Python           | 3.5.1    |
| PLY              | 3.7      |
| have readline    | True     |
| prompt toolkit   | None     |
| shell type       | readline |
| pygments         | 2.1.1    |
| on posix         | True     |
| on linux         | True     |
| distro           | debian   |
| on darwin        | False    |
| on windows       | False    |
| on cygwin        | False    |
| is superuser     | False    |
| default encoding | utf-8    |
+------------------+----------+

mjbright avatar Jun 22 '16 12:06 mjbright

Adding full traceback on Ubuntu

Traceback (most recent call last):
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/xonsh/base_shell.py", line 154, in default
    run_compiled_code(code, self.ctx, None, 'single')
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/xonsh/codecache.py", line 57, in run_compiled_code
    func(code, glb, loc)
  File "", line 3, in 
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/IPython/core/display.py", line 152, in display
    format = InteractiveShell.instance().display_formatter.format
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/traitlets/config/configurable.py", line 405, in instance
    inst = cls(*args, **kwargs)
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 499, in __init__
    self.init_io()
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 670, in init_io
    io.stdout = io.IOStream(sys.stdout)
  File "/home/mjb/anaconda3/lib/python3.5/site-packages/IPython/utils/io.py", line 37, in __init__
    setattr(self, meth, getattr(stream, meth))
  File "/home/mjb/anaconda3/lib/python3.5/tempfile.py", line 750, in softspace
    return self._file.softspace
AttributeError: '_io.StringIO' object has no attribute 'softspace'

mjbright avatar Jun 22 '16 12:06 mjbright

Hi @mjbright, does that same code work for you in a regular python kernel?

blink1073 avatar Jun 22 '16 12:06 blink1073

Yes, I just retested it with the Python3 kernel to be sure.

mjbright avatar Jun 22 '16 13:06 mjbright

That is a real bummer that a StringIO object would not have the same interface as a file object.

blink1073 avatar Jun 22 '16 15:06 blink1073