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.
Install VS Code and the Python extension
Section titled “Install VS Code and the Python extension”An extension is an add-on that gives VS Code new features.
-
Download VS Code from code.visualstudio.com and install it.
-
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).
-
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 project folder
Section titled “Open the project folder”Open the whole folder, not single files. VS Code then finds your environment and your data.
- Choose File → Open Folder…
- 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.
Select the interpreter
Section titled “Select the interpreter”VS Code must know which Python to use. Point it at the environment in .venv.
-
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.
-
Type
Python: Select Interpreterand press Enter. -
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.
Run a file
Section titled “Run a file”-
Create a file: File → New File…, and save it in
my-courseascheck_python.py. The.pyending tells VS Code that it is a Python file. -
Type this code and save:
check_python.py import sysprint(sys.version_info >= (3, 12))Output True -
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
Section titled “The integrated terminal”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:
python check_python.pyInstall Ruff
Section titled “Install Ruff”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.
-
Open the Extensions view again.
-
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:
ruff check .ruff format .ruff check . lists problems in every Python file in the current folder (. means “this folder”). ruff format . formats every file.
Format on save
Section titled “Format on save”Let VS Code format each Python file and sort its imports every time you save.
-
In
my-course, create a folder called.vscode. -
In that folder, create the file
settings.jsonwith this content:.vscode/settings.json {"[python]": {"editor.defaultFormatter": "charliermarsh.ruff","editor.formatOnSave": true,"editor.codeActionsOnSave": {"source.organizeImports": "explicit"}}} -
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.
Next step
Section titled “Next step”Learn the two ways to run Python and how to read the code on this site: Running code.