Exporting a Jupyter Notebook to Markdown


This guide demonstrates four ways to export a Jupyter notebook to a Markdown file:

  1. Using the Command Line
  2. From within a Notebook Cell
  3. Using Python Code
  4. Through the Jupyter Lab Web Interface

Using the Command Line

You can use the jupyter nbconvert command-line tool to convert your notebook to a Markdown file. Here’s the specific command you need to run:

jupyter nbconvert --to markdown mynotebook.ipynb

Note: If your notebook includes images, executing this command will create an additional directory named mynotebook_files.

To verify the operation, you can list the contents of your current directory:

$ ls
mynotebook_files  mynotebook.ipynb

From within a Notebook Cell

You can also run the nbconvert command from within a Jupyter notebook cell by preceding the command with an exclamation mark (!):

!jupyter nbconvert --to markdown mynotebook.ipynb

Using Python Code

Another way to convert a notebook to Markdown is by using Python’s os module to execute the nbconvert command:

import os
os.system('jupyter nbconvert --to markdown mynotebook.ipynb')

Through the Jupyter Lab Web Interface

Lastly, you can use the Jupyter Lab web interface to export your notebook to Markdown:

Navigate to File -> Save and Export Notebook As… -> Markdown.

Jupyter Notebook Export Markdown