{"id":7307,"library":"install-playwright","title":"Install Playwright Browsers from Python","description":"install-playwright is a Python library that provides a programmatic way to execute the `playwright install` CLI command, which downloads browser binaries (Chromium, Firefox, WebKit) required by the Playwright automation library. This allows Python applications to manage Playwright browser installations directly, without needing to shell out to a subprocess. The current version is 1.0.0, and it follows an infrequent release cadence, primarily updating for compatibility or minor feature additions.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/eggplants/install-playwright-python","tags":["web automation","playwright","browser installation","testing"],"install":[{"cmd":"pip install install-playwright","lang":"bash","label":"Install install-playwright"},{"cmd":"pip install playwright","lang":"bash","label":"Install Playwright (required dependency)"}],"dependencies":[{"reason":"install-playwright is a wrapper around the Playwright CLI's `install` command, thus the Playwright library itself must be installed to provide the necessary BrowserType objects (p.chromium, etc.) and underlying CLI functionality.","package":"playwright"}],"imports":[{"note":"This imports the function to trigger browser installation.","symbol":"install","correct":"from install_playwright import install"},{"note":"Necessary to get browser type objects (e.g., p.chromium) which are passed to install_playwright.install.","symbol":"sync_playwright","correct":"from playwright.sync_api import sync_playwright"}],"quickstart":{"code":"from playwright.sync_api import sync_playwright\nfrom install_playwright import install\n\nwith sync_playwright() as p:\n    # Install Chromium browser binaries\n    print(\"Installing Chromium...\")\n    install([p.chromium])\n    print(\"Chromium installed.\")\n\n    # Optionally, install other browsers\n    # print(\"Installing Firefox and WebKit...\")\n    # install([p.firefox, p.webkit])\n    # print(\"Firefox and WebKit installed.\")\n\n    # Example of using Playwright after installation\n    browser = p.chromium.launch()\n    page = browser.new_page()\n    page.goto(\"http://example.com\")\n    print(f\"Page title: {page.title()}\")\n    browser.close()","lang":"python","description":"This quickstart demonstrates how to use `install_playwright` to programmatically install Playwright browser binaries. It first imports `sync_playwright` from the main `playwright` library to access browser type objects, then calls `install()` with the desired browser types. After installation, it includes a simple Playwright usage example to verify successful setup."},"warnings":[{"fix":"Ensure both `pip install playwright` and `pip install install-playwright` are run. Always install `playwright` first.","message":"The `install-playwright` library only handles the *installation of browser binaries* (Chromium, Firefox, WebKit). It does NOT install the `playwright` Python package itself. You must `pip install playwright` separately.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use a `with sync_playwright() as p:` block (for synchronous usage) or `async with async_playwright() as p:` (for asynchronous usage) and pass `p.chromium`, `p.firefox`, or `p.webkit` to the `install` function.","message":"The `install` function expects `BrowserType` objects from the `playwright` library (e.g., `p.chromium`). You must initialize `playwright.sync_api.sync_playwright` or `playwright.async_api.async_playwright` to obtain these objects before calling `install_playwright.install`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To install only Chromium, use `install([p.chromium])`. To install multiple specific browsers, use `install([p.chromium, p.firefox])`.","message":"By default, `install_playwright.install()` will install all supported browsers if called without arguments, similar to `playwright install`. To install specific browsers, you must pass a list of `BrowserType` objects.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Wrap your `install` call within a `with sync_playwright() as p:` block or ensure `p` is available from an `async_playwright` context.","cause":"The `p` object (representing the Playwright context) was not initialized or is out of scope when calling `install_playwright.install([p.chromium])`.","error":"NameError: name 'p' is not defined"},{"fix":"Run `pip install playwright` before installing `install-playwright` or attempting to use it.","cause":"The main `playwright` Python library has not been installed, which is a prerequisite for `install-playwright` and for providing the `BrowserType` objects.","error":"ModuleNotFoundError: No module named 'playwright'"},{"fix":"Ensure you pass a list to the `install` function, even if it contains only one browser, e.g., `install([p.chromium])` instead of `install(p.chromium)`.","cause":"The `install` function expects a list of `BrowserType` objects, but a single `BrowserType` object was passed directly without being wrapped in a list.","error":"TypeError: 'BrowserType' object is not iterable"}]}