sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

jupyter2 to pdf export exception #2442

Closed haraldschilly closed 3 months ago

haraldschilly commented 7 years ago

I saw this when trying to export an ipynb via latex to pdf:

[NbConvertApp] ERROR | Notebook JSON is invalid: {'data': {'image/png': '033261260f3456095aaa80aaa24aa72b3b00930d'}, 'metadata': {'image/png': {'width': 699, 'height': 410}}} is not valid under any of the given schemas

Failed validating 'oneOf' in code_cell['properties']['outputs']['items']:

On instance['cells'][7]['outputs'][0]:
{'data': {'image/png': '033261260f3456095aaa80aaa24aa72b3b00930d'},
 'metadata': {'image/png': {'height': 410, 'width': 699}}}
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/ipython_genutils/ipstruct.py", line 132, in __getattr__
    result = self[key]
KeyError: 'output_type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/jupyter-nbconvert", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/nbconvertapp.py", line 313, in start
    self.convert_notebooks()
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/nbconvertapp.py", line 481, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/nbconvertapp.py", line 452, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/nbconvertapp.py", line 381, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/exporter.py", line 172, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/exporter.py", line 190, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/pdf.py", line 162, in from_notebook_node
    nb, resources=resources, **kw
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/latex.py", line 82, in from_notebook_node
    return super(LatexExporter, self).from_notebook_node(nb, resources, **kw)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/templateexporter.py", line 268, in from_notebook_node
    nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/exporter.py", line 132, in from_notebook_node
    nb_copy, resources = self._preprocess(nb_copy, resources)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/exporters/exporter.py", line 309, in _preprocess
    nbc, resc = preprocessor(nbc, resc)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/preprocessors/coalescestreams.py", line 30, in wrappedfunc
    nb.cells[index], resources = function(cell, resources, index)
  File "/usr/local/lib/python3.5/dist-packages/nbconvert/preprocessors/coalescestreams.py", line 72, in coalesce_streams
    if output.output_type == 'stream' and '\r' in output.text:
  File "/usr/local/lib/python3.5/dist-packages/ipython_genutils/ipstruct.py", line 134, in __getattr__
    raise AttributeError(key)
AttributeError: output_type
haraldschilly commented 7 years ago

The real question is how the notebook ended up in that state. The code was matplotlib related with an plt.show() at the end. That code alone works. It's probably not a jupyter bug at all, just some upstream issue or some input conversion.

williamstein commented 7 years ago

It could be an interaction between classical and modern jupyter. The incorrect output is precisely the internal format used by cocalc (modern jupyter) for images -- so this has absolutely nothing to do with upstream.

There's no way to reproduce this given here, but I'll leave this open (at least so long as we keep classical jupyter) in case somebody has any ideas...

williamstein commented 3 months ago

closing due to lack of example.