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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Exporting Jupyter Notebooks

Give Feedback

Jupyter Notebook supports exporting Notebooks into the following formats:

  • LaTeX
  • PDF
  • RevealJS
  • Markdown
  • ReStructured Text
  • Executable script

In this lesson you’ll learn how to export Notebooks to these formats using the File menu and the nbconvert tool.

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?

00:39 One thing that might be pretty useful and is something that I use often is to export it to HTML or to a Python file, a .py file. Let’s try to do this first, export it as a .py file.

00:54 Okay, we’ll keep this. It downloads it, fine.

01:01 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 nbconvert tool.

01:33 So, when I head back over to our Notebook server, I’m going to create a new terminal in here.

01:42 And in here, I’m going to run the command. It’s a relatively simple command that doesn’t take a lot of input: jupyter nbconvert, and then I give it the filename.

01:53 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:13 And this went pretty quick, it’s already finished. We can see that now we additionally have this .html file. Let’s take a look at how it looks like.

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.

02:50 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.

03:15 But you can go ahead and install that, and then this works just in the same way. So, that’s the quick walk-through on how to convert a Jupyter Notebook into different formats.

03:25 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.

03:53 But again, Jupyter gives us helpful instructions on how to proceed. And that wraps up the section on exporting. We ended with a nice error message.

Vincenzo Fiorentini on March 27, 2019

This was quite useful. I noticed that the pdf export does not render well some of the markdown; may be it’d be preferable to export to html and then print to pdf from there.

Great course, anyway !

Eric P on Aug. 15, 2019

jupyter nbconvert jupyter/my\ notebook.ipynb --to HTML

give me this traceback stack

Traceback (most recent call last):
  File "/Users/epalmer/miniconda3/bin/jupyter", line 7, in <module>
    from jupyter_core.command import main
ModuleNotFoundError: No module named 'jupyter_core'

Ranit Pradhan on March 18, 2020

Actually I’m using Windows 10 and this command isn’t working [PS F:\Softwares\Jupyter Notebook> jupyter nbconvert DS(Jupyter Notebook).ipynb – to HTML]

Martin Breuss RP Team on March 18, 2020

Hi @RanitRP, make sure that you are using the correct command:

jupyter nbconvert --to HTML your_notebook_name.ipynb

Note the double-dash and no space with --to. HTML is the default format, so you can even avoid specifying the format for that. Check out the official documentation for more info.

Become a Member to join the conversation.