A virtual environment is an isolated Python environment with its own installed packages, so each project's dependencies don't conflict. pip installs packages; requirements.txt pins them for reproducibility.
python -m venv .venv creates an environment; you activate it (source .venv/bin/activate) so pip install selenium pytest installs into that isolated environment, not system Python. pip freeze > requirements.txt captures exact versions, and pip install -r requirements.txt reproduces them on another machine or in CI — the Python equivalent of package-lock.json. Isolation prevents 'works on my machine' issues from clashing global packages. Tools like pipenv/poetry add lockfiles and dependency resolution on top.
A CI job runs python -m venv .venv && pip install -r requirements.txt so the test suite uses the exact Selenium/pytest versions the author tested with — no surprise version drift.
Two projects need different Selenium versions and keep breaking each other. What's the fix?