By Nobody 2026-07-22

PythonCoding

Introduction

The Quarto publishing looks useful for writing with Jupyter notebooks.

Install Quarto

mkdir ~/opt
tar -C ~/opt -xvzf quarto-1.9.38-linux-amd64.tar.gz

Create a symlink to bin/quarto in a folder that is in your path. If there is no such folder, you can create a folder such as ~/.local/bin and place the symlink there. For example:

mkdir ~/.local/bin
ln -s ~/opt/quarto-1.9.38/bin/quarto ~/.local/bin/quarto

Try running; if not in the path update PATH in .bashrc.

quarto -v

Use quarto check to confirm installation.

quarto check

Might get: [✓] Checking Python 3 installation….OK Version: 3.14.6 Path: /usr/bin/python3 Jupyter: (None)

    Jupyter is not available in this Python installation.
    Install with python3 -m pip install jupyter

So install Jupyter

python3 -m pip install jupyter

And run quarto check again.

Hello, Quarto

Follow the Quarto tutorial. Create a file named hello.qmd, add the tutorial content from Quarto website. Try to create final output for the .qmd:

pip install numpy matplotlib
quarto render hello.qmd --to html
quarto render hello.qmd --to docx

Preview

To see a live preview in a web browser:

quarto preview hello.qmd

As per the tutorial, edit line 19, changing from theta = 2 * np.pi * r to theta = 4 * np.pi * r. The live preview should update.

Cell Options

Cell options are written in YAML using a specially prefixed comment (#|). At the start of the block with the figure these are used for a caption and label.

#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"

Computations

Follow the tutorial on to this section.

python3 -m pip install jupyter matplotlib plotly pandas

Create another file named computations.qmd.

If in the front-matter we add echo:false the all python code is hidden rather than just one cell. Try it.

---
title: Quarto Computations
execute:
    echo: false
jupyter: python3
---

You might want to selectively enable code echo for some cells. To do this add the echo: true cell option. Try this with the NumPy cell.

#| echo: true

import numpy as np
a = np.arange(15).reshape(3, 5)
a

Code Folding

Rather than hiding code entirely, you might want to fold it and allow readers to view it at their discretion. You can do this via the code-fold option. Remove the echo option we previously added and add the code-fold HTML format option.

---
title: Quarto Computations
format:
  html:
    code-fold: true
jupyter: python3
---

You can also provide global control over code folding. Try adding code-tools: true to the HTML format options.

---
title: Quarto Computations
format:
  html:
   code-fold: true
   code-tools: true
jupyter: python3
---

Inline Code

In addition to code cells, you can also include code inline in the markdown sections of your document. To include an executable expression, enclose it in {python} . For example, you can use inline code to state the number of observations in the gapminder data. Try adding the following markdown text to your Quarto document.

There are `{python} len(gapminder)` rows in the `gapminder` data.