Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Jupyter Notebooks Extensions

Jupyter allows you to add new functionality to Notebooks through extensions. In this lesson, you’ll see where to get extentions, how to install them, and how to enable and disable them using an extension manager.

Download

Course Slides (PDF)

414.8 KB

00:00 The last point I want to talk about in this tutorial are Jupyter Notebook extensions. There’s a whole lot of them, and I’m going to show you the easiest way to get started exploring them.

00:12 So, we head over to our terminal that we opened up using Jupyter. And in here, I’m just going to copy-paste pip install for jupyter_contrib_nbextensions.

00:24 You can find the GitHub link to this repository also in the written tutorial. This is just going to install a couple of extensions that are useful and that we’re going to try out.

00:40 Okay, so I already had those installed, that’s why it’s coming up as already satisfied, but otherwise it would have installed this. And the next thing we’re going to grab is a Notebook extensions configurator, which is a useful tool for enabling and disabling specific extensions without having to do it from the command line.

01:01 So, I’m also fetching this from GitHub and just copy-pasting to install here.

01:08 All right, this is done. And the last thing I need to do now is I need to enable this Notebook extension. Generally, you would have to do this with every single one of the extensions, but using this extension manager, we’d only need to activate this one and then we can do the rest of them through a graphical user interface.

01:31 Here’s the command to enable it. We’re using a jupyter command for this, jupyter nbextensions_configuratorso, that would be the name of whatever extension you want to activate—and then you say enable to activate it, disable for disabling it.

01:46 And we’re just going to do this for our --user.

01:53 After calling this, it’s telling us that “Fine, okay, this extension is now enabled,” and now we’ll have to restart Jupyter Notebooks in order to be able to use the extension.

02:04 So I’ll go ahead and do that from my command line.

02:15 Now restart it…

02:27 And here we are. We see now the Nbextensions tab here on our Notebook server. I’ll go ahead and click that. And here you can see a long list of pre-installed extensions that came with this package that we downloaded from GitHub. There’s a lot of them.

02:44 Most of them I don’t know. I tried out some of them and want to just show you two or three so that you have an idea of what you’re able to do with these extensions, and then I’d just encourage you to go ahead and explore. And these are by far not all of them. The community built a lot of other extensions, and if you’re savvy with JavaScript, just go ahead and build your own.

03:09 I’m going to activate Scratchpad, and that just works through clicking here, and I’m going to activate the Variable Inspector. You can also read up on what does it do down here.

03:21 The Variable Inspector collects all the variables, and you can take a look at them and what’s currently defined. That sounds useful. And yeah, there’s a lot of them. I just encourage you to try them out.

03:34 There’s syntax highlighting, there’s code autocompletion, there’s PEP8 linting. There’s an extension that allows you to publish your Notebook as a Gist right away. Let’s activate that too, and go over to our Notebook to take a look.

03:56 Since I restarted the Notebook server, I also have to start the kernel for our Notebook again. I restructured it a bit, took away most of the Markdown. And here, now we can see—after activating these extensions—I can see these things popping up here, and one of them is down here.

04:14 So, what do we have? I’m going to run these two cells, so I put these two variables in memory, and now using the Variable Inspector I can take a look in this floating window—I can move it around—and it tells me what’s the current value of all of the different variables that are currently defined inside of my Notebook. I can sort them by Name, Type, Size, or Value. So, that’s one example. Then there’s the Scratchpad, which essentially, from what it seems, is just a mini Notebook, right in here.

04:51 I can create variables in here, execute them in the same way that I do without Notebook extensions. Print out, play around, and try it out. And these variables that I define in here are even available inside of the Notebook afterwards, so I could go ahead and print out b.

05:17 Another extension that could be fun and helpful for some people is this Gist-it. I can just click this button and then right from here, create a public Gist. There’s a possibility also to sign in with your account, to then have the Gist associated to your GitHub account.

05:38 So, I guess it requires authentication to create a Gist. So, these are just some quick examples of possible ways that you can extend your Jupyter Notebooks. As you saw, there’s a lot of them and there’s many more.

05:56 If you’re interested, if there’s something specific that you want, go ahead and take a look if it exists, or otherwise write it yourself and contribute to the community.

06:05 There’s probably some people who are going to be thankful for it.

06:11 This wraps up this short tutorial on getting started using Jupyter Notebooks. I hope you enjoyed it, and I hope I inspired you to go ahead and explore a little. See you next time!

Avatar image for jjbwoollyback

jjbwoollyback on Nov. 28, 2023

I followed the lesson but am having problems installing the nbextensions. When I clickon the nbextensions menu option I get a list of extensions unfortunately all have a no-entry or stop sign icon. I am using macos Sonoma 14.1.1 on Apple M1

Avatar image for Martin Breuss

Martin Breuss RP Team on Nov. 29, 2023

@jjbwoollyback and @magnoliacodes I think that the team made some updates to the extensions manager since recording time.

You can access it from the main menu. Make sure that Settings → Enable Extension Manager is checked, and then you can navigate to it through View → Extension Manager.

In that view, you can search for extensions and install them, and view the extensions you already have installed.

Can you give it a try whether that works for you?

Avatar image for markprubin

markprubin on Dec. 3, 2023

(venv) markrubin@Marks-MacBook-Pro realpython-course % jupyter nbextensions_configurator enable --user            
Traceback (most recent call last):
  File "/Users/markrubin/Development/realpython-course/venv/bin/jupyter-nbextensions_configurator", line 5, in <module>
    from jupyter_nbextensions_configurator.application import main
  File "/Users/markrubin/Development/realpython-course/venv/lib/python3.9/site-packages/jupyter_nbextensions_configurator/__init__.py", line 18, in <module>
    from notebook.base.handlers import APIHandler, IPythonHandler
ModuleNotFoundError: No module named 'notebook.base'

This is the error I am getting in my terminal once I get to this command.

However, in my extension manager, this is what I see.

Extension manager screengrab

Is this sufficient?

Avatar image for Martin Breuss

Martin Breuss RP Team on Dec. 6, 2023

@markprubin yeah I think I bumped into the same error when I tried this the other day. Your screengrab looks good, it seems like you properly installed the extensions using the Extension Manager. 🙌

Can you work with them?

Avatar image for arthur55

arthur55 on Dec. 21, 2023

Hello,

Do you have to install packages such as jupyter_contrib_nbextensions from inside your Notebook server? Or will it also work if you install them off the server, i.e. on your computer’s terminal (in the correct cwd and with the virtual environment activated)? I’m just wondering why there is a difference between the two, and what the difference is… Thanks in advance.

Avatar image for Martin Breuss

Martin Breuss RP Team on Dec. 22, 2023

@arthur55 as long as you make sure you’re installing them into the same environment that you’re running Jupyter in, then I think this should work fine.

The Notebook you view in your browser is just a graphical user interface that makes it more straightforward to interact with (including installing extensions).

Avatar image for arthur55

arthur55 on Dec. 25, 2023

Thanks for your response Martin. Apologies if I’m wrong but I don’t think this has been resolved already, although someone else encountered the same error message. I keep getting errors when trying to activate the configurator. This time I’ve tried to activate it from my terminal (Powershell), not on a J.N. server, using the command from the tutorial. The last line of the error message is

ModuleNotFoundError: No module named ‘notebook.base’

Do you know how I can resolve this? Many thanks.

Avatar image for Martin Breuss

Martin Breuss RP Team on Jan. 3, 2024

@arthur55 yeah I think there’s been a change in how this extension manager works. I took a look and posted about it a bit further up and I think it might be best to just use the built-in extension manager at this point.

Avatar image for Ignacio Romero

Ignacio Romero on June 19, 2024

Hi, I was able to install the jupyter extension, but when I try to enable them, it doesn’t work and I can not get the extension tab in the interface. Any idea?

Thanks

Avatar image for Martin Breuss

Martin Breuss RP Team on June 24, 2024

Hi @Ignacio Romero how did you install the extensions? Did you approach it like described in the comment further up?

Become a Member to join the conversation.