Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter Notebook to HTML - Notebook JSON is invalid: ['outputPrepend']

I am trying to convert my Jupyter Notebook file (.ipynb) into an HTML file for easier reading. Every time I try to save the notebook I get a "Notebook validation failed" error:

Notebook validation failed: ['outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend'] has non-unique elements:
[
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend",
 "outputPrepend"
]

message when file is saved

When I try to download as .html using File > Download as, I get a further more detailed error but I still cannot make out what it means or what needs to be done to solve the problem and finally download as HTML:

nbconvert failed: ['outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend', 'outputPrepend'] has non-unique elements

Failed validating 'uniqueItems' in code_cell['properties']['metadata']['properties']['tags']:

On instance['cells'][70]['metadata']['tags']:
['outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend',
 'outputPrepend']

message when trying to download as HTML

This is only happening on the specific notebook I am working on. I have tried to save and export other notebooks as HTML successfully.

Any help is appreciated. Thanks

like image 731
Jaume Clave Avatar asked Apr 08 '20 15:04

Jaume Clave


People also ask

How to convert HTML to Jupyter noteboks (.ipynb)?

How to Convert HTML to a Jupyter Notebook (.ipynb) 1. Import BeautifulSoup, json, & urllib; 2. Setting a Custom User-Agent; 3. Read the URL; 3. Use BeautifulSoup to Scrape the HTML; 4. Create Jupyter Notebook Metadata with json; 5. Getting the Code Elements from the HTML; Conclusion: How to Convert HTML to Jupyter Noteboks (.ipynb)

How do I export a Jupyter Notebook as a Python file?

You can export a Jupyter Notebook as a Python file (.py), a PDF, or an HTML file. To export, select the Export action on the main toolbar. You'll then be presented with a dropdown of file format options. Note: For PDF export, you must have TeX installed.

Do you use Jupyter notebook to program?

I rarely use Jupyter Notebook to program, because I am not accustomed to a grid of code blocks, which makes me uncomfortable. But today when I opened Jupyter Notebook to read other people's code, I was surprised to find a few big words on Jupyter Notebook page:

How to fix corrupted Jupyter Notebook?

Something just corrupted a Jupyter notebook that I use for testing. This is a fairly big and complicated notebook with lots of ipywidgets. More importantly, the problem is fixed by executing Cell -> All Output -> Clear Despite this, the notebook seems to function correctly. Thanks for the detailed description. We now depend on nbformat 4.2.0.


Video Answer


1 Answers

I recently experienced this from using the VSCode Notebook editor. I solved it by opening the notebook in a regular text editor and deleting all the extra outputPrepend-items, leaving only a single one in each array.

like image 133
Jacob Lauritzen Avatar answered Oct 18 '22 17:10

Jacob Lauritzen