Manuals / Playwright with Python / Chapter 7
Part 1 · Foundations · beginner · ~45 min · Chapter 7 of 61
2. Environment Setup
Installing Python, pip, virtual environments Assuming Python is installed, the critical habit here is virtual environments (venv). Every project should get its own isolated environment: python -m venv venv source venv/bin/activate # Mac/Linux venv\Scripts\activate # Windows Why this matters beyond "best practice" advice: different projects may need different Playwright/pytest versions, and install
Step 1 of 1
Overview
Installing Python, pip, virtual environments Assuming Python is installed, the critical habit here is virtual environments (venv). Every project should get its own isolated environment: python -m venv venv source venv/bin/activate # Mac/Linux venv\Scripts\activate # Windows Why this matters beyond "best practice" advice: different projects may need different Playwright/pytest versions, and installing everything globally eventually causes version conflicts that are painful to debug. Get in the habit now, before you have multiple projects to manage. Installing Playwright + browser binaries Two separate steps that beginners often miss the distinction between: The first installs the Python package (the API you write code against). The second downloads the actual browser binaries (Chromium, Firefox, WebKit) — Playwright doesn't use your system-installed Chrome; it ships its own pinned browser builds. This is deliberate: it guarantees every developer and every CI machine runs the exact same browser version, eliminating "works on my machine" bugs caused by browser version drift. If you skip playwright install, your tests will fail immediately with a clear error telling you the browser executable wasn't found. Project folder structure Even a simple starting structure pays off later (this is a preview of Chapter 14's POM and Chapter 29's scalable architecture): project/ ├── tests/ ├── pages/ (page object classes — comes later) ├── conftest.py ├── pytest.ini └── requirements.txt Starting with even this loose structure — rather than dumping every test file flat in one folder — means you won't need a painful reorganization once the suite grows past a handful of tests.
Try it
Run / study this snippet
pip install pytest-playwrightChapter learning outcomes
- Installing Python, pip, virtual environments Assuming Python is installed, the c
- Every project should get its own isolated environment: python -m venv venv sourc
Clear these before you leave
Side quest
2. Environment Setup deliverable
Apply one idea from “Overview” in a small script or note.