How to save changes in read-only Jupyter Notebook

Viewed 18860

I have opened a python Jupyter notebook but did not notice that it was in read-only, Not Trusted mode. How to save my changes now?

Things that I have tried and did not help:

  • File -> Make a Copy
  • File -> Save and Checkpoint
  • File -> Download as
  • File -> Trust Notebook
6 Answers

One hack around this issue:

  1. Select all cells (or cells that you need) in your read-only notebook. You can select all cells by clicking on the first cell and then shift+clicking the last cell.
  2. Copy all cells using CTRL+C (COMMAND+C if you are using MAC)
  3. Create a new jupyter notebook page
  4. Click CTRL+V (COMMAND+V if you are using MAC) twice
  5. Save your new notebook

Hope this hack helps

As mentioned here, you can easily run the following command (it's resolved my problem as well):

sudo chmod 777 <notebook_file_name>

Here's a more technical answer that provides a server-side solution that can be used from the command line or programatically.

https://jupyter-notebook.readthedocs.io/en/latest/notebook.html#introduction

Trusting Notebooks To prevent untrusted code from executing on users’ behalf when notebooks open, we store a signature of each trusted notebook. The notebook server verifies this signature when a notebook is opened. If no matching signature is found, Javascript and HTML output will not be displayed until they are regenerated by re-executing the cells.

Any notebook that you have fully executed yourself will be considered trusted, and its HTML and Javascript output will be displayed on load.

If you need to see HTML or Javascript output without re-executing, and you are sure the notebook is not malicious, you can tell Jupyter to trust it at the command-line with:

$ jupyter trust mynotebook.ipynb 

See Security in notebook documents for more details about the trust mechanism.

  1. Open the notebook in a text editor as a text file.
  2. You should find a JSON like structure
  3. Change "editable": false, to "editable": true, under "metadata"

I agree with the first answer above, but you must include one more step (STEP 4 below) in order for all cells copied to not be pasted into a single cell.

1) Select all cells (or cells that you need) in your read-only notebook. You can select all cells by clicking on the first cell and then shift+clicking the last cell.
2) Copy all cells using CTRL+C (COMMAND+C if you are using MAC)
3) Create a new jupyter notebook page

4) CLICK IN THE MARGIN OF THE NEW CELL (***to close it for editing***), then...

5) Click CTRL+V (COMMAND+V if you are using MAC) 
6) Save your new notebook

By default Jupyter inserts the cursor into the first cell, which opens it for editing.

To avoid pasting everything into the cell that is open for editing you must close it for editing.

You can navigate to the following tabs - View --> Cell Toolbar --> Edit Metadata

Now, all the cells will have 'edit metadata', click on it and set the 'editable' to 'true' or just delete that json entry. The cells will now be editable :)

note: you might have to do this for every cell in the notebook you wanna edit

Related