Selenium + Python · Lesson 12 of 43

0/43 done

Module 12: Python Environment & Packages

12. Virtual Environments (venv), pip & Dependency Management

14 minlesson

Your task

Implement format_requirements_entry(package_name, version):

  1. Return f"{package_name}=={version}".

Write it in the editor, then press Check answer (Ctrl + Enter).

Virtual Environment Workflow

bash
# 1. Create virtual environment:
python -m venv .venv

# 2. Activate environment:
# Windows PowerShell:
.venv\Scripts\Activate.ps1
# macOS / Linux:
source .venv/bin/activate

# 3. Install packages:
pip install selenium pytest

# 4. Freeze dependencies:
pip freeze > requirements.txt

# 5. Install from requirements file on CI:
pip install -r requirements.txt

Key Takeaways & Walkthrough Summary

Managing Python environments with venv guarantees that your test framework dependencies do not conflict with system packages. In this lesson, you will master creating virtual environments, installing packages with pip, and freezing requirements.txt. Let's master environments!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why should I pin versions with '==' in requirements.txt?

Pinning exact versions prevents breaking upstream changes from crashing your test runs unexpectedly on CI agents.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip