[Updated 2016-03-04 to support Jupyter 4 notebooks – see below.]
IPython notebooks are stored in a format that is not particularly human-readable and doesn’t work well in version control.
One way to solve this problem is to automatically export the code from IPython notebooks into a vanilla Python file after each save.
It’s also useful to automatically generate a HTML file of the notebook on each save. This can be done manually in Jupyter (File > Download as > HTML), but if you always want this, doing it automatically is much easier.
Use the following code to automatically save a
.py and a
.html file when you save a notebook in Jupyter. These two files will be saved in the same folder as the parent
ipython locate profile default, which will give you the path to save the following code in.
Save the code below in this folder as
ipython notebook. You will see an error message in the terminal if there are any syntax or runtime errors with
ipython_notebook_config.py. If everything looks good, go to your web browser, open a notebook, and click the Save/Checkpoint button (it’s the floppy disk icon in the Jupyter toolbar). You should see a
.py and a
.html file appear alongside your
Update for Jupyter 4 notebooks
After the big split between IPython and Jupyter, and the accompanying update to Jupyter 4.x, the config file above no longer works. Instead, put the following in a file saved at ~/.jupyter/jupyter_notebook_config.py to achieve the same thing:
This code could be DRYer, but it does work.
🌟 Was this page helpful? Please let me know with this quick, 3 question survey.