Why and how to automatically save Jupyter notebook to .py files
September 9, 2017 ยท View on GitHub
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?
- 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. - 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.