Automatically install / enable nbextension during pip / conda install

111 views
Skip to first unread message

Tomasz Gandor

unread,
Apr 6, 2018, 6:27:06 AM4/6/18
to Project Jupyter
I'm contributing to a library based on ipywidgets, which is a notebook extension.
Right now, after installing via pip or a .whl file the user needs to issue 2 jupyter nbextension commands (install and enable).

Ipywidgets needs at most one (enable) or even none at all (their readme mentions that notebook 5.3 or higher is needed).

What needs to be done in our library so that we also can "work out of the box"?

Best regards,
Tomasz Gandor

Nicholas Bollweg

unread,
Apr 10, 2018, 1:20:51 AM4/10/18
to Project Jupyter
Hi Tomasz!

tl; dr: Luckily, since you are working on widgets, you can get a taste of how automagic installing would work before trying it on your project with the widget cookiecutter, which includes the conf.d approach.

Historically, most nbextensions on conda ran the first script (nbextension install) at build time, and ran the second script (nbextension enable) in post-link scripts: here are a bunch of examples. If you are in the position of having to support older notebook installs, this is your best bet, even though at the bottom of the page it warns pretty harshly against these scripts. And yeah, they do create problems.

Pure python package distributions have been able to put files in arbitrary locations relative to their install for a long time. Here's how ipywidgets does it, with a combination of data_files, package_data and include_package_data. In that last line of data_files, you'll see a reference to a directory, namely etc/jupyter/nbconfig/notebook.d/ . As of this PR, which landed in 5.3, an nbextension package only needs to write a single file to that location to be enabled by default in the environment where it was installed. Hooray! Of course, you end up with some more files in your repo, more stuff in setup.py and MANIFEST.in, etc. Boo! But it should be a small, one-time effort for you, and more streamlined for your users forever. Hooray!

Thanks for bringing this up! It should definitely get some official documentation: PR started! Give it a review, any comments welcome!

Hooray!

nick
Reply all
Reply to author
Forward
0 new messages