Playwright for Python supplies the API that drives Chromium, Firefox, and WebKit from Python scripts or tests. Keeping it inside a project virtual environment keeps the browser driver and dependencies tied to that project instead of the system interpreter.
The PyPI package installs the Python bindings and Playwright CLI, but browser engines are downloaded separately with the Playwright install command. Each Playwright release expects matching browser builds, so the browser install step belongs with the package install and should be rerun after upgrading the package.
On minimal Ubuntu hosts, python -m playwright install --with-deps chromium can install the Linux libraries that browser processes need before the first launch. The sample project path is ~/projects/playwright-python-demo; use the matching virtual environment activation command for Windows or macOS, and install additional browser engines only when the project runs against them.
Related: Create a Python virtual environment
Related: Install Python packages with pip
Related: Install Playwright with npm
Steps to install Playwright with Python:
- Change to the Python project directory.
$ cd ~/projects/playwright-python-demo
- Confirm that the project interpreter meets the current Playwright package requirement.
$ python3 --version Python 3.14.4
Current Playwright releases on PyPI require Python 3.10 or newer. Use the interpreter that will own the project environment.
- Create a virtual environment for the project.
$ python3 -m venv .venv
The command normally returns no output on success.
Related: Create a Python virtual environment - Activate the virtual environment.
$ source .venv/bin/activate
On Windows, activate the environment from .venv\Scripts instead.
Related: Activate a Python virtual environment - Install the Playwright Python package into the active environment.
$ python -m pip install playwright Collecting playwright ##### snipped ##### Installing collected packages: typing-extensions, pyee, greenlet, playwright Successfully installed greenlet-3.5.3 playwright-1.61.0 pyee-13.0.1 typing-extensions-4.16.0
Exact dependency versions and wheel filenames vary by platform and package-index state. The important signal is that pip installs playwright into the active virtual environment.
Related: Install Python packages with pip - Install Chromium and the Linux libraries needed to launch it.
$ python -m playwright install --with-deps chromium Installing dependencies... ##### snipped ##### Downloading Chrome for Testing 149.0.7827.55 (playwright chromium v1228) Chromium 149.0.7827.55 downloaded to ~/.cache/ms-playwright/chromium-1228
Use a shell that can install system packages when --with-deps is used on Linux. Omit --with-deps on macOS or Windows, and omit chromium when the project needs the default Chromium, Firefox, and WebKit browser set.
- Confirm that the installed Playwright CLI is available through the environment.
$ python -m playwright --version Version 1.61.0
- Launch Chromium with a short Python smoke test.
$ python - <<'PY' from playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.set_content("<title>Playwright fixture ready</title>") print(page.title()) browser.close() PY Playwright fixture ready
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.