Skip to content

Your editor

An editor is the program where you write code. This course uses VS Code (Visual Studio Code). It is free, runs on macOS, Windows and Linux, and has good Python support. Any editor works, but the steps on this page are for VS Code.

An extension is an add-on that gives VS Code new features.

  1. Download VS Code from code.visualstudio.com and install it.

  2. Open VS Code. Click the Extensions icon in the left bar (four small squares), or press Cmd + Shift + X (macOS) or Ctrl + Shift + X (Windows, Linux).

  3. Search for Python and install the extension published by Microsoft. It also installs Pylance (code completion and error hints) and the Python Debugger.

Open the whole folder, not single files. VS Code then finds your environment and your data.

  1. Choose File → Open Folder…
  2. Select my-course, the folder from Virtual environments.

The Explorer panel on the left now lists .venv, requirements.txt and, later, your data folder and scripts.

VS Code must know which Python to use. Point it at the environment in .venv.

  1. Open the Command Palette: Cmd + Shift + P (macOS) or Ctrl + Shift + P (Windows, Linux). The Command Palette is a search box for every VS Code command.

  2. Type Python: Select Interpreter and press Enter.

  3. Pick the entry that shows .venv. It is often marked as recommended.

The Python version and the environment name now appear in the status bar at the bottom right. VS Code remembers the choice for this folder.

  1. Create a file: File → New File…, and save it in my-course as check_python.py. The .py ending tells VS Code that it is a Python file.

  2. Type this code and save:

    check_python.py
    import sys
    print(sys.version_info >= (3, 12))
    Output
    True
  3. Click the Run Python File button (a triangle) at the top right of the editor. VS Code opens a terminal panel and runs the file with the selected interpreter.

The terminal panel shows the command that VS Code ran, then the output True.

The integrated terminal is a terminal inside VS Code. Open it with View → Terminal, or press Ctrl + ` (the backtick key, left of 1 on most keyboards) on every system.

It starts in the project folder. When you open a new terminal, VS Code activates the selected environment for you, so python is the Python in .venv. Check the prompt: it starts with the environment name. You can run any course command here, for example:

Terminal
python check_python.py

Ruff is a fast linter and formatter for Python. A linter reads your code and warns about likely mistakes, for example an unused import or a variable that does not exist. A formatter rewrites the layout of your code (spaces, line breaks, quotes) into one consistent style, so you never fix layout by hand.

  1. Open the Extensions view again.

  2. Search for Ruff and install the extension published by Astral Software.

Ruff now underlines problems in your code as you type. Hover over an underline to read the message. Ruff is also in your course environment, so you can run it in the terminal:

Terminal
ruff check .
ruff format .

ruff check . lists problems in every Python file in the current folder (. means “this folder”). ruff format . formats every file.

Let VS Code format each Python file and sort its imports every time you save.

  1. In my-course, create a folder called .vscode.

  2. In that folder, create the file settings.json with this content:

    .vscode/settings.json
    {
    "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit"
    }
    }
    }
  3. Save the file.

charliermarsh.ruff is the ID of the Ruff extension. The settings apply only to Python files in this project folder. To test them, add extra spaces to a line, for example x = 1, and save. Ruff changes it to x = 1.

Learn the two ways to run Python and how to read the code on this site: Running code.