Exporting Jupyter Notebooks
Jupyter Notebook supports exporting Notebooks into the following formats:
- ReStructured Text
- Executable script
In this lesson you’ll learn how to export Notebooks to these formats using the File menu and the
00:00 In this part of the tutorial on Jupyter Notebooks, we’re going to talk about how to export a Notebook that we just finished, and what are the different options that we have, and how to go about doing it.
00:12 So, here I’m back in our Notebook that we were working on before. It has some code cells, it has some Markdown cells, and now we want to export this so we can present it to our team, for example.
00:24 The easiest way to do this is go to the File menu and say File > Download as, and here we can see we have a couple of options—actually, quite a lot of options. This list just keeps going, right?
Okay, now I downloaded the file and since it is a normal file download, it ends up inside of my
Downloads/ folder. So, I’ve headed over to my desktop and here in my
Downloads/ folder, we can now see the Python file that was just downloaded. A different way of exporting files from within the Notebooks that also keeps the files in the directory that we’re currently working in is the
We’re going to use the Notebook that I just created before,
jupyter_test, and then the flag
--to, and then you give it a file type extension—one of the supported file types, there’s a lot of them. I’m going to convert it to HTML.
02:32 We can see that it flawlessly converted to HTML because everything that’s used in here—it’s just a big JSON file, essentially, so it’s easy to convert it to HTML and we can see everything that was part of our Notebook nicely displayed and easily shareable as an HTML file.
As we saw before in the Notebook’s menu, there’s a lot of possible file extensions that you can convert to. Some of them have additional dependencies. So if I try, for example, to convert this Notebook to PDF, I’m going to get an error… because I don’t have
pandoc installed, which is a dependency for converting the Notebook into a PDF file.
Either do it with the relatively simple
nbconvert command on your terminal—remember the
--to flag and be aware that some of these file extensions have dependencies—or you can do it directly from inside of your Notebook through the File menu > Download as. And same here, if you don’t have the correct dependencies installed, then—well—the PDF is not going to work out.
Become a Member to join the conversation.