Run py5 sketches from VS Code with one click, the way Processing and Thonny's py5 plugin do. The extension handles both imported mode (size(400, 400), no py5. prefix) and module mode (import py5). It also stops VS Code from underlining every rect, fill and mouse_x as an error.
This is a community extension. The py5 project doesn't make or endorse it.
What it does
▶ Run Sketch. A play button in the editor title bar, or Cmd+R (Mac) / Ctrl+R (Windows, Linux).
Detects the mode:
a file with import py5 runs as normal Python;
any other file runs through py5's imported-mode runner.
Where it runs: the sketch runs from its own folder, so load_image("photo.jpg") finds files next to it. Errors and print() output appear in a terminal panel.
Rerun: pressing Run again restarts the sketch.
■ Stop Sketch. The stop button, or Cmd+Shift+R / Ctrl+Shift+R. Closing the sketch window works too.
Imported-mode editor support. When you open an imported-mode sketch, the extension offers to add a small __builtins__.pyi file to the folder. The file lists exactly the names your installed py5 provides in imported mode. Pylance (VS Code's Python checker) then knows py5's names:
squiggles under size, rect and mouse_x go away;
autocomplete and hover show py5's own documentation;
real typos like rectt are still flagged, and so are np and os when you haven't imported them.
Set Up py5 and Java. One command installs py5 into the selected Python interpreter. If you don't already have Java, it also downloads Java 21 into ~/.jdk.
Java detection. If JAVA_HOME isn't set, the extension points py5 at the newest Java in ~/.jdk. That's where py5-install-jdk and the Thonny py5 plugin put it.
Snippets:
py5sketch and py5module for a new sketch;
py5grid for a nested-loop grid;
py5mouse and py5key for event functions.
Reference. Right-click a word and choose Open Reference for Word Under Cursor to open py5's documentation page for it.
Getting started
Install the Python extension. VS Code offers it automatically when you install this one.
Open the folder that holds your sketches (File → Open Folder…).
Pick a Python interpreter: open the Command Palette and run Python: Select Interpreter.
Open the Command Palette and run py5: Set Up py5 and Java (once per computer). Skip this step if py5 already works on your computer.
Interpreter for sketches. Empty uses the Python extension's interpreter.
py5.javaHome
(empty)
Java 17+ folder. Empty uses JAVA_HOME, then the newest ~/.jdk.
py5.offerEditorSupport
true
Offer to turn on editor support for imported-mode folders.
py5.focusTerminalOnRun
false
Move keyboard focus to the terminal when a sketch starts.
Notes
Editor support covers the whole folder. The __builtins__.pyi file applies to every file in the folder. A module-mode file there that calls rect() without py5. won't be underlined, though it will still fail when run.
Strict type checking. Some py5 functions are typed loosely: random() can return a number or an array. If you turn on strict type checking (python.analysis.typeCheckingMode), you'll see a few false warnings such as "float | NDArray". The default setting (off) shows none.
Live coding and Jupyter aren't covered. Use py5's own py5-live-coding tool or the py5 Jupyter kernel for those.