Skip to content

Python Virtual Environment Sandbox Explorer

Run MicroSim in Fullscreen

Specification

The full specification below is extracted from Chapter 15: Software Setup and the Developer Environment on the Raspberry Pi 5.

Type: interactive-infographic
**sim-id:** python-venv-sandbox-explorer<br/>
**Library:** p5.js<br/>
**Status:** Specified

Learning objective: Students will *explain* (Bloom L2: Understand) how a Python virtual environment isolates one project's package dependencies from another project's.

Canvas: 700x460px, responsive — recompute box positions as fractions of `width`/`height` inside `windowResized()`, stacking the two project boxes vertically below 560px wide instead of side by side.

Layout: a "System Python" box at the top, with two separate boxed "sandboxes" below it labeled "Project A: venv (numpy 1.x)" and "Project B: venv (numpy 2.x)," each drawn with a distinct border color (indigo `#3F51B5` and raspberry `#C2185B`). Small package icons (simple labeled circles) sit inside each sandbox, showing that each has its own copy of shared library names, possibly at different version numbers.

Interaction: clicking "Install numpy 1.x" or "Install numpy 2.x" buttons (`createButton()`, one per sandbox) animates a package icon dropping into that sandbox only, while the other sandbox and the System Python box visibly remain unchanged — demonstrating that the install has no effect outside its own sandbox. A `createButton()` labeled "Reset Sandboxes" empties both sandboxes back to their starting state. Hovering any package icon shows a tooltip with its exact version number.

Implementation: p5.js. Each sandbox tracked as an array of installed package objects `{name, version}`. Button clicks push a new object into the clicked sandbox's array only. Redraw all packages inside their sandbox's bounding box each frame from that sandbox's array, arranging them in a simple grid that grows as packages are added.