Sunday, April 10, 2016

Default template for iPython notebook (using Jupyter)

Leave a Comment

In the first cell of every iPython (Jupyter) notebook, I almost always type:

%matplotlib inline import matplotlib.pyplot as plt import numpy as np 

Is there a way to make it so that this cell appears at the top of each new notebook I create by default?

For example, could I save a template .ipynb file somewhere, which is copied by iPython when creating a new notebook?

(I found this question, but it seems to be more about css than default content in cells.)

1 Answers

Answers 1

I know it may not be what you're looking for (this example is not good for working on notebooks that need to be run in multiple environments, e.g. shared), but I put the following in a file called ipython_config.py in my .ipython folder.

c.InteractiveShellApp.exec_lines = ['%matplotlib inline',     'import numpy as np',     'import scipy.constants as c',     'import scipy.integrate as sci',     'from mpl_toolkits.mplot3d import Axes3D',     'import scipy.optimize as sco' ] 

This runs before anything runs in any interactive console, including the jupyter notebook. If you want explicit boilerplating, I think that you will be disappointed (unless you want to build in the functionality for us ☺)

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment