Notebook Validation Failed | Jupyter

Question:

A frustrating and persistent error keeps popping up on my Jupyter Notebook:

The save operation succeeded, but the notebook does not appear to be valid. The validation error was:

Notebook validation failed: Additional properties are not allowed ('id' was unexpected):
{
 "metadata": {
  "trusted": true
 },
 "id": "breathing-seventh",
 "cell_type": "code",
 "source": "import pandas as pdnimport numpy as npnimport renimport datetimennimport jsonnimport osnimport copynnimport seaborn as snsnimport matplotlib.pyplot as plt",
 "execution_count": 1,
 "outputs": []
}

It points to my imports column which contains:

import pandas as pd
import numpy as np
import re
import datetime

import json
import os
import copy

import seaborn as sns
import matplotlib.pyplot as plt

I’m also using Plotly in the notebook and I’m unsure if the error was caused by Plotly. I looked up the error and used the fixes mentioned here but the error still persists.

Please Advise.

Asked By: The Singularity

||

Answers:

I had this error with older notebooks in virtualenvs with older python packages. It usually disappears when I update all my python packages in that virtualenv.

Answered By: Toby

This is due to a fairly recent change in nbformat, which was described in detail here. Basically, nbformat 4.5 introduced these id tags (which you’ll probably find in every cell if you look for them), so every notebook stored in an earlier format should not have those tags — if an early-format notebook has them, it’s considered an error.

So somehow your notebook was partially updated to have id tags, but not the nbformat listed in the notebook’s metadata. This has also happened to me, and it’s surely a bug. (I think the update is supposed to happen via nbformat, in which v5.1.1 will automatically convert 4.x up to 4.5; but I have 5.1.2. That and every other package are as up-to-date as conda will give me, and I’ve restarted my jupyter server.)

Anyway, the way to solve this problem is to open up your notebook in a text editor (which could be Jupyter Notebook’s built-in text editor if you temporarily change the .ipynb extension to .txt). Scroll to the very bottom, where the last few lines should look something like this:

 },
 "nbformat": 4,
 "nbformat_minor": 1
}

You should be safe to change that nbformat_minor number to 5, save the file, and open the notebook again as usual. You won’t get those notifications again.

Answered By: Mike

I was able to solve this by running

conda update --all
Answered By: Alauddin Sabari

I faced this problem when I pasted the cells from notebook-1 to notebook-2.

The simple solution is if you have your code in a cell that you would intend to reuse, then don’t copy the cell but only copy the content in the cell.

In this way, I was able to resolve the error.

Answered By: acesaif
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.