A Python virtual environment keeps a project's installed packages separate from the packages used by other projects. Create one with python -m venv .venv using the Python interpreter you want, then run the project's commands with the interpreter inside .venv. That isolates dependencies. The code still runs with your usual user permissions.
What isolation means here
Imagine two projects that depend on different versions of a package. Installing both sets into one shared environment can make the result difficult to reproduce. Separate environments let each project keep the dependencies it expects.
The project source remains outside .venv. Treat the environment as something you can recreate. Keep the source, README, dependency information, tests, and useful fixtures as the durable parts of the project.
Create, then invoke explicitly
Use the intended interpreter's -m venv command to create an environment. On Windows, its executable normally lives under .venv\Scripts; on Linux, under .venv/bin. The paths differ because the operating systems arrange executables differently.
Activation changes shell convenience settings so a short python command resolves to the environment. It is optional. Calling the environment's executable directly is especially helpful in tutorials and scheduled tasks because the command itself shows which environment is intended.
Install only what the project needs
Use the selected interpreter's -m pip when a project has third-party dependencies. That connects installation to a known Python rather than an unrelated pip executable elsewhere on the machine. Prefer the project's stated dependency list to guesses based on an import error.
Projects 001 and 005 use the standard library. After a suitable full Python installation is available, their runtime code does not need a third-party package installation. An environment can still be useful for learning consistency.
Keep dependency records meaningful
Record direct dependencies and the versions used for a release. Reproducibility also depends on Python, operating system, inputs, and configuration. A list of package versions is useful evidence, not a complete description of the machine.
Do not copy an environment between Windows and Linux or assume moving it to a different path will work. Recreate it with the appropriate interpreter and install the recorded requirements. Keep .venv out of source control and backups intended to preserve source history.
Use the environment’s Python without activating the shell
Use the explicit executable path instead of weakening a machine-wide shell policy. On a managed device, follow the organisation's installation and execution rules. The objective is a clear project environment, not a workaround for controls you are not authorized to change.
If the terminal works but the editor runs a different Python, select the same interpreter in VS Code.