A Python interpreter executes a program, while a virtual environment gives that interpreter an isolated package installation location.
Python interpreter and virtual environments: run the intended executable
Operation contract
The runtime probe checks the version before doing work and identifies whether its interpreter belongs to an environment. Create an environment with python3 -m venv .venv, then install through .venv/bin/python -m pip on POSIX systems or .venv\Scripts\python.exe -m pip on Windows. That command names the interpreter that owns the installation. An unrelated pip executable can install into another runtime without changing the application you later run.
Failure and ownership boundary
Environment isolation is package isolation, not a process sandbox. The fixture uses only the standard library and performs no installation. It deliberately prints a stable version-range result rather than claiming every machine has an identical patch version. Python modules: separate import-time definitions from program execution and Python receipt CLI project: parse options and report failed input need the same interpreter ownership rule.
Working program
import sys
def supported_runtime(version):
return version >= (3, 11)
print("runtime supported:", supported_runtime(sys.version_info[:2]))
print("old runtime supported:", supported_runtime((3, 9)))Output
runtime supported: True
old runtime supported: FalseCosts and limits
The version comparison has fixed-size work. Creating an environment writes interpreter support files and installing dependencies adds network/disk cost. Those operations are not timed or performed by this program.
Common Mistakes
- Install with the interpreter that runs the application.
- A virtual environment is not a security sandbox.
Connected lessons
Python modules: separate import-time definitions from program execution, Python receipt CLI project: parse options and report failed input.
Apply this boundary
Python pyproject.toml: build a wheel and inspect its metadata.
Follow the related contract
Python input and output: separate parsing from terminal I/O, Python type conversion: parsing success is not field validity.
Check the next state boundary
Python keywords and identifiers: parser rules differ from field rules, Python compatibility checks: parse syntax and execute contracts as separate evidence.
