user697911
user697911

Reputation: 10531

How to save a file into a directory in Jupyter notebook?

I invoke "jupyter notebook" under:

 [abigail@localhost anaconda3]$ jupyter notebook

By default, it saves to the directory of anaconda3/ with an extension of "ipynb" when I click "File" => "Save".

How to save it to a directory under anaconda3/, instead of the default location? There is not a "save as" command in notebook?

Upvotes: 20

Views: 124019

Answers (3)

Natheer Alabsi
Natheer Alabsi

Reputation: 2870

There are two methods:
1.You can use the magic command %notebook to save as ipynb

  %notebook "directory/to/file/filename.ipynb"     

2.You can use the magic command %%writefile to save as py file

  %%writefile "directory/to/file/filename.py"

In the second method, you should put this command at the top of the cell, otherwise it will throw an error.

Upvotes: 8

Manosh T Manoharan
Manosh T Manoharan

Reputation: 21

It is easiest to select a destination before you create a program using Jupyter Notebook; as then you do not run into this issue.

However, since you have already made a program, one possible solution is to make a copy of the file, move it to your desired location, and then delete the old file. Before doing this, ensure that you have saved it first, otherwise data might be lost.

Upvotes: 2

mbecker
mbecker

Reputation: 657

You can save a notebook to a location of your choice by using the "File" -> "Download as" -> "Notebook (.ipynb)" option from the menu.

Alternatively you can start your notebook server from a different directory and it will save all notebooks to that directory.

A third option is to navigate to the directory you want the notebook to be saved to in the tree view "http://127.0.0.1:8888/tree" prior to creating the notebook.

Upvotes: 26

Related Questions