How to document the launch of a Jupyter Notebook profile?

When I start the Jupyter Notebook, I changed ipython_config.py in my ipython profile to automatically load numpy as np :

 c.InteractiveShellApp.exec_lines = [ 'import numpy as np', ] 

This works great. When I start the laptop, in the first cell I can immediately call the entire numpy library via np. . However, if I share this laptop using the gist method or some other method, this import is not explicitly displayed. This is suboptimal because it makes clear reproducibility impossible.

My question is: Is it possible to automatically fill the first cell of a new laptop with the code that I import? (Or another similar way to document the import that occurs for a laptop).

I would be fine with removing the exec_lines option and pre-populating the code that I have to run myself or some other solution that falls into the main idea: explicit reproducibility of the code that I initially import into the notebook.

Edit

A remote answer that may be useful for people landing here: I found jupyter_boilerplate , which as an installable extension for a laptop β€œAdds a custom menu item for Jupyter (IPython) to insert snippets of template code” - will make it easy to create a snippet of source code that can to be filled.

Sidenote MLavoie because "comments are disabled for deleted / blocked messages / reviews"

Yes, you are right that:

While this link can answer the question, it’s better to include the main parts of the answer here and provide a link for reference. Response links may become invalid if the linked page changes. - From Review - MLavoie Jun 8 '16 at 17:27

But you will notice that this is a widget that needs to be installed, so there is no corresponding code here. Incorrectly delete the above answer.

+6
source share
2 answers

Almost automatically:

%load startup.py

Put the import / configuration code in the versioned file on PYTHONPATH and% load it into the first cell.

The advantage of this is that you can use a different startup code without configuring the startup configuration, and laptops remain portable, that is, send the laptop and startup file to other users, and they can run it without configuring the startup configuration.

+4
source

Create a notebook that contains the drugs you need, and use it as a template. That is, copy it to a new file and open it.

-1
source

Source: https://habr.com/ru/post/986007/


All Articles