1  Python, VS Code, Quarto

2 Python, VS Code, Quarto

2.1 Install Python

2.1.1 Search Engine

  1. Search “Python for VS Code”
  2. Go to https://code.visualstudio.com/docs/languages/python
  3. Click “Python Tutorial”
  4. Click “Install Python for python.org”

2.1.2 Python.org

  1. Click “Download Python 3.XX.X”
  2. Open the installer from Downloads
  3. Check both boxes when the “Setup” prompt comes up.
  4. After the install, select “Disable path length limit”

2.1.3 Test Python

  • Windows Key
  • Type “terminal”
  • In terminal, type “python”
  • In Python, type:
print("hello world")
hello world

2.2 Install VS Code

2.2.1 Aside

  • It is of great benefit to us as learners that VS Code includes “Copilot” (LLM) integration.

2.2.2 Install

  1. Go to https://code.visualstudio.com/
  2. Click “Download for Windows”
  3. Open the installer from Downloads
  4. Check all four boxes when the “Setup” prompt comes up.
  5. After the install, select “Launch Visual Studio Code”

2.2.3 VS Code Setup

  1. Use Copilot, or don’t.
  2. Choose your theme
  3. Select “Browse Language Extensions”
  4. Click through the remaining options.

2.2.4 Python extension setup

  1. Create a new Python project
  2. Create a new folder, likely Documents/DATA505
  3. Create a file “hello.py”:
hello.py
# hello.py

print("hello world")
  1. Click the [>] button to run the file, which should print out to the terminal:
  1. Return to the Python tutorial.
    • Click “CSelect Python Interpreter”
    • Select the version of Python you installed earlier.

2.3 Install Quarto

2.3.1 Search Engine

  1. Search “Quarto”
  2. Go to https://quarto.org/
  3. Click “Get Started”
  4. Click “Download Quarto CLI”

2.3.2 Install Quarto

  1. Run the Installer
    • All default options are fine.
  2. Install the VS Code Extension.
  3. Setup Python for Quarto

2.4 Install Jupyter

*To work with .qmd files, Python needs a package akin to R “languageserver”

  1. Go to https://quarto.org/docs/get-started/hello/vscode.html
  2. Run the following terminal command:
    • If you lost your terminal, create a new one from the menu.
    py -m pip install jupyter matplotlib plotly
    • This will take a moment.
  3. Following the Quarto tutorial, make hello.qmd
  4. Click “Run Cell” in hello.qmd on this cell:
import numpy as np
import matplotlib.pyplot as plt

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
  subplot_kw = {'projection': 'polar'} 
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
Figure 2.1: A line plot on a polar axis
  1. When prompted, install the ipykernel
  2. I restarted VS Code.

2.5 Cleanup

2.5.1 Quarto Preview

  1. To test whether the process worked, open hello.qmd in VS Code.
  2. Quarto preview hello.qmd either by pressing [>] or by using ctrl+shift+k.
  3. After a moment, a document will be displayed, in VS Code and if you wish, in browser.

2.5.2 Render .md

To make this document.

  1. Prefix the .md document with a .qmd header:
---
title: "Python, VS Code, Quarto"
format:
  html:
    code-fold: true
jupyter: python3
---
  1. Rename from fname.md to fname.qmd
    • I did this by creating a new file and using copy+paste
  2. Use quarto render fname.qmd either:
    • In the VS Code integrated terminal, or
    • At the command line, e.g. Windows Key+“terminal”