Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtconsole ipython 0.13.2 - html/xhtml export fails #3807

Closed
kfiz opened this issue Jul 27, 2013 · 13 comments · Fixed by #4054
Closed

qtconsole ipython 0.13.2 - html/xhtml export fails #3807

kfiz opened this issue Jul 27, 2013 · 13 comments · Fixed by #4054

Comments

@kfiz
Copy link

kfiz commented Jul 27, 2013

Hi,
I'm having problems trying to export qtconsole sessions to html/xhtml on my linux box(Macbook Pro). I'm running python 3.3.2.
The html export fails with:

'Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/IPython/frontend/qt/console/rich_ipython_widget.py", line 71, in export_html
    super(RichIPythonWidget, self).export_html()
  File "/usr/lib/python3.3/site-packages/IPython/frontend/qt/console/console_widget.py", line 615, in export_html
    self._html_exporter.export()
  File "/usr/lib/python3.3/site-packages/IPython/frontend/qt/rich_text.py", line 80, in export
    if inline is None and IMG_RE.search(html):
TypeError: can't use a string pattern on a bytes-like object'

The xhtml export fails with :
'Type string doesn't support the buffer API'
Am I doing something wrong?

Cheers

@minrk
Copy link
Member

minrk commented Jul 27, 2013

Probably a unicode-handling bug in our code that only affects Python 3.

@stonebig
Copy link
Contributor

Isn't it an issue that #4043 may suddenly solve ?
(4 common keywords : "png" + (unexpected "bytes-like") + "py3k" + "to html")

@Carreau
Copy link
Member

Carreau commented Aug 16, 2013

nop. Qtconsole has nothing to do with ipynb files.

@stonebig
Copy link
Contributor

Hello,

On my windows pc
Trying with http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash_control.html

With Python 2.7 / ipython 0.13.2 or ipython 1.0.0rc1, everything works (inlining or not inlining the png).

With Python 3.3 / ipython 1.0.0 (patched with 4043), it asks me where to save the .html, then the "inline / external" question doesn't show up, then I get in the dos windows the same message
\IPython\qt\rich_text.py", line 80, in export
if inline is None and IMG_RE.search(html):
TypeError: can't use a string pattern on a bytes-like object

remark


Trying to digg further , I found a reference to a remark from GaelVaroquaux
"# in python3, StringIO does not accept binary data"
(joblib/joblib@e53cc2b)

*** privileged python 2 users behavior below ****
qt_to_html_python2_ipython1

@stonebig
Copy link
Contributor

I don't know if it can help a competent "doctor", but If I spy the "image_tag" coming to ensure_utf8(image_tag)
I see, with print(image_tag.class)

  • gives a "type 'instancemethod'" for python 2.7
  • gives a "class 'method'" for python 3.3

@minrk
Copy link
Member

minrk commented Aug 17, 2013

It's a fairly straightforward bug: when saving to HTML, we explicitly encode to utf8 bytes, rather than leaving as unicode, which is pretty clearly inappropriate. PR #4054 should address the issue, though I don't have access to a Python 3 environment with working Qt, so it needs some help testing.

@stonebig
Copy link
Contributor

Hello MinRK,

I confirm that, under windows32 bit, python3.3, ipython2.0.0dev, it solves the issue

  • export with "png" inline works great,
  • export with "png" external works as great.
    ==> Another Hourra for minRK ... \o/ ...\o/ ... \o/ ... !

Looking further, there is an option ".xhtml" just below the ".html" one.

If I try it now out of the box

  • it doesn't fail either, like it was yesterday,
  • but it asks me an obscure message
    "cannot convert png to svg. to fix this add c.InlineBackend.Configure.figure_format = 'svg' "

The message is much less limpid than the option to launch it, which is 'odd' for a newcomer.
But isn't XHTML just 'dead' ? http://en.wikipedia.org/wiki/Extensible_HyperText_Markup_Language

@minrk
Copy link
Member

minrk commented Aug 18, 2013

It's a bit silly to call it 'xhtml', the main thing is that it is HTML with inline SVG, and you can only do that if your figures are SVGs. If you add that config %config InlineBackend.figure_format = 'svg' before making plots, the SVG export should work.

@stonebig
Copy link
Contributor

ok,

I type that in my qt console
It then default to "xhtml" backup
But then it sends me the "cannot convert png to svg. to fix this add c.InlineBackend.Configure.figure_format = 'svg' " message again.
same after a relaunch of kernel. (but maybe it's my winpython installation problem)
(ok solved , the config must be done before doing matplotlib figures)

@minrk
Copy link
Member

minrk commented Aug 18, 2013

Hm, I will have to test with Python 3 to make sure there isn't another issue to fix (there may well be).

@stonebig
Copy link
Contributor

I didn't try 'xhtml' in python2 either ... let see
(stupid me : i must change the configuration before doing the graphic, I guess)

  • It sort of blows up under ipython 0.13 / python 2.7 'ascii codec can't encode characters in position 9988-9990'
    • back to ipython 2.0 dev / Python 3 doing %config InlineBackend.figure_format = 'svg' BEFORE doing the matplotlib action, it works

minrk added a commit to minrk/ipython that referenced this issue Aug 19, 2013
not utf8-encoded bytes

should close ipython#3807
@kfiz
Copy link
Author

kfiz commented Aug 20, 2013

I'm not at my box at the moment. I'll check in a few hours.

@kfiz
Copy link
Author

kfiz commented Aug 21, 2013

Works like a charm. Tried out the xhtml/inline export. Thanks!

minrk added a commit that referenced this issue Aug 27, 2013
not utf8-encoded bytes

should close #3807
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
not utf8-encoded bytes

should close ipython#3807
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants