Cannot not open Jupyter Notebook

File Load Error for Basics.ipynb

Unreadable Notebook

Please read Getting good answers to your questions.
We’d need more information to have any hope of assisting you in sorting this out.

Some ideas to get you started considering how to help us help you:

  • Where is this notebook? Saved or stored on your machine?
  • Did you try opening it with a text editor and compare it to a typical structured json file of a notebook that works?

Other things to maybe clarify:
How did you install Jupyter? And if you didn’t install it, what are you using or from where?

That is in no way an exhaustive list. They are just meant to get you started.

Thanks for your reply, Wayne.

I am working on a Dataquest Portfolio Project: “Predicting The Weather Using Machine Learning” – 8 of 11. Lesson 8 is where I did a “prediction model”. It was after this when I started having problems with the Notebook. The “Basic.inpynb” file appears to have gotten corrupted. I’m getting the following error message:

File Load Error for Basics.ipynb

Unreadable Notebook: /home/jovyan/Basics.ipynb NotJSONError(‘Notebook does not appear to be JSON: '{\n “cells”: [\n {\n “cell_type”: "m…’)

I’ve done as much troubleshooting as I know. I noticed that I can open this file with the editor, but not with Notebook or JSON.I compared the editor layout with another known good Basic.ipynb file – the patterns seems to be the same here. , I have tried 3 different browsers (Edge, Chrome & Firefox); these all give the same error message. I also turned off my Windows firewall – no change either.

Incidentally, I am using a Windows 11 desktop, logged into the remote environment provided by Dataquest. This environment has been working just fine for several weeks now, and for many lessons thus far.

Regards,

J. Price

JSON is very strict, download the ipynb file, rename it to .json and open it in vs code. Do you see any Red dots on the scrollbar? Maybe then you can guess the problem then, or you can post the error you get when hovering the red underlined area.

So that is promising that you should at least be able to get a good outcome after some effort.

Be sure to look around and see if there are old timepoints saved before the notebook document got messed up.

Worse-case scenario is you grab the text from the text editor and build up a new version of the notebook.
Perhaps nbformat can still open it? If so, you have programmatic options:

See here for some trick on how to copy code cells using nbformat. I only reference that because it has more details about what is going on. That one only gets you code cells text.

You should be able to grab all the text in code and markdown with this code run in a new notebook along:

import nbformat as nbf

ntbk = nbf.read("your_notebook.ipynb", nbf.NO_CONVERT)

# Collect content of input code cells and markdown cells
filtered_cells = [c for c in ntbk.cells if c.cell_type in ['code', 'markdown']]

new_ntbk = nbf.v4.new_notebook(cells=filtered_cells)
new_ntbk.metadata['name'] = "My Filtered Notebook"

# add cell id identifiers
_, new_ntbk = nbf.validator.normalize(new_ntbk)

with open("extracted_code_and_markdown.ipynb", "w", encoding="utf-8") as f:
    nbf.write(new_ntbk, f)

This will only work though if nbformat can open the problematic one. Given how messed up it sounds, maybe not?