Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the IPython Notebook have "initialization cells"?

When I open a saved IPython Notebook, I need to evaluate all the cells with imports, function definitions etc. to continue working on the session. It is convenient to click Cell > Run All to do this. But what If I do not want to re-evaluate all calculations? Do I need to pick the cells to evaluate by hand each time?

For this problem, Mathematica has the concept of "initialization cells". You can mark some cells in the notebook as initialization cell, and then perform "evaluate initialization cells" after opening the notebook.

Does the IPython Notebook have a similar solution?

like image 907
clstaudt Avatar asked Feb 18 '13 10:02

clstaudt


People also ask

What is the difference between Jupyter Notebook and IPython notebook?

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.

How do you initialize a Jupyter Notebook?

Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start the Jupyter Notebook App. The notebook interface will appear in a new browser window or tab. A secondary terminal window (used only for error logging and for shut down) will be also opened.

Do Jupyter notebooks have code cells and markdown cells?

Recall that a Jupyter Notebook file consists of a set of cells that can store text or code. Text Cells: Text cells allow you to write and render Markdown syntax. This is where you can describe and document your workflow. Code Cells: Code cells allow you to write and run programming code (e.g. Python ).


2 Answers

First, when you open an IPython notebook, this does not mean the state of the kernel is lost, unless you restarted the server or explicitly stop the kernel.

Otherwise, there are no marked cell, but there is a "run until here" on dev version.

Also if you are using dev version, using Cell Toolbar /metadata and I would say ~30 line of javascript it should be doable.

I suggest you open an enhancement request on main issue tracker. This could typically be made as an extension during a sprint and/or a blog post to explain internal of notebook.

like image 89
Matt Avatar answered Sep 29 '22 12:09

Matt


If you're using the latest and greatest of the notebooks (mine is > 4.1), the feature you requested is available through an extension.

The extensions, as well as an interface that can be conveniently used to enable/disable each individual extension, can be installed as follows

$ git clone https://github.com/ipython-contrib/IPython-notebook-extensions.git
$ cd IPython-notebook-extensions
$ ./setup.py

When you have installed the extension, start the notebook server

$ cd ; jupyter-notebook < /dev/null > .jupiter.log 2>&1 &

and go to the extension management page

$ xdg-open http://localhost:8888/nbextensions

In the recently opened browser window, enable the "Initialization cells" extension.

If you open now a notebook of yours, in the toolbar you will see a new icon, similar to a hand-held calculator and in the View/Cell Toolbar a new entry, Initialisation Cell.

Enable this menu entry and click on the cells' toolbar which ones you want to mark as an initialization cell (possibly remove the cells' toolbar) and click on the icon previously described...

When you load a notebook, the initialization cells are automatically run, so that if you want you can place them in a convenient place, say the end of the notebook if you're like me...

like image 21
gboffi Avatar answered Sep 29 '22 12:09

gboffi