Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default template for iPython notebook (using Jupyter)

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.)

like image 710
Bill Cheatham Avatar asked Nov 30 '15 15:11

Bill Cheatham


People also ask

What is the default path for Jupyter Notebook?

Configuration files Config files are stored by default in the ~/. jupyter directory.

Is IPython notebook and Jupyter Notebook same?

The IPython Notebook is now known as the Jupyter Notebook. It is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. For more details on the Jupyter Notebook, please see the Jupyter website.

Does Jupyter Notebook come with IPython?

The name, Jupyter, comes from the core supported programming languages that it supports: Julia, Python, and R. Jupyter ships with the IPython kernel, which allows you to write your programs in Python, but there are currently over 100 other kernels that you can also use.


2 Answers

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 scc',     '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 ☺)

like image 196
Riet Avatar answered Sep 28 '22 04:09

Riet


There is a pretty cool solution using jupyterlab: jupyterlab_templates

Installation took about 5 minutes and you can have as many

templates as you'd like.

Mac Users

Assuming you have conda installed than during the installation, you'll need to install node js engine:

  • conda install -c conda-forge nodejs

And create a jupter_noteook_config.py if you don't have one :

  • jupyter notebook --generate-config
like image 43
oopsi Avatar answered Sep 28 '22 06:09

oopsi