Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 1.58 KB

save_notebook_as_py_file.md

File metadata and controls

29 lines (24 loc) · 1.58 KB

Why and how to automatically save Jupyter notebook to .py files

Why save a jupyter notebook as a python file?

Because notebooks are hard to version control - try git diff [YOUR_NOTEBOOK].ipynb after a few changes and see the mess.

How to save a juypter notebook as a python file?

  1. Most obvious way is to manually download from the notebook: File -> Download as -> Python (.py), find the python file from the Downloads folder, and copy to your repository.
  2. A slightly better way is to run from the command line:
$ jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

or run the schell command in jupyter notebook:

!jupyter nbconvert --to script [NOTEBOOK_NAME].ipynb

How to automatically save a jupyter notebook as a python file?

Follow this post and save this python file (jupyter_notebook_config.py) as ~/.jupyter/jupyter_notebook_config.py.

How to automatically save a jupyter notebook as a python file when you're running the notebook in a docker container?

Add jupyter_notebook_config.py to the .jupyter folder in the dockerfile:

ADD jupyter_notebook_config.py [HOME]/.jupyter/

See here for example.

References: