Check Playwright Installation and Fix Browser Issues
In this article
To check if Playwright is installed and its browsers are correctly configured, run pip show playwright to verify the package and playwright install to ensure the required browser binaries are present. This process ensures that the Python library is linked to the necessary Chromium, Firefox, and WebKit engines required to execute automation scripts without crashing.
What You'll Need
- A computer with Python 3.8 or newer installed.
- A terminal or command prompt (CMD, PowerShell, or Bash).
- Pip (Python package manager) updated to the latest version.
- Administrative privileges (required for some system-level browser dependencies).
Step-by-Step
- Verify the Playwright Python Package: Open your terminal and type
pip show playwright. If installed, the terminal will display the version number, location, and summary. If you see "Package(s) not found," you must install it usingpip install playwright. - Test the CLI Accessibility: Run
playwright --version. This confirms that the Playwright command-line interface is mapped to your system's PATH. If the command is not recognized, you may need to restart your terminal or check your Python Scripts folder. - Check for Installed Browsers: Playwright does not install browsers via pip; it uses a separate command. To see if browsers are present, try running a simple script or use the command
playwright install. While this command is typically used for installation, running it again will check for missing binaries and download only what is necessary. - Verify Browser Functionality: Create a small test file named
test_pw.pywith the following code:
Run it usingfrom playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch() print("Browser launched successfully!") browser.close()python test_pw.py. If it prints "Browser launched successfully!", your installation is complete. - Install System Dependencies: If the browser fails to launch on Linux or certain Windows environments, run
playwright install-deps. This command installs the necessary OS-level libraries (like libgbm or nss) that the browsers need to run in headless mode.
Common Mistakes
- Confusing Pip with Browser Install: Many users assume
pip install playwrightinstalls the browsers. It only installs the Python API. You must runplaywright installseparately. - Virtual Environment Neglect: Installing Playwright globally but running scripts in a virtual environment (venv) often leads to "ModuleNotFoundError." Always ensure you are in the active environment where the package was installed.
- Ignoring Version Mismatches: If you update the
playwrightpip package, the existing browser binaries may become incompatible. You must runplaywright installagain after every major package update. - Running as Non-Admin on Linux: Attempting to install dependencies (
install-deps) without sudo privileges will result in permission errors.
Tips
- Selective Installation: To save disk space, you can install only one browser instead of all three. Use
playwright install chromiumorplaywright install firefox. - Use Headed Mode for Debugging: When checking if things work, use
p.chromium.launch(headless=False). Seeing the browser window open provides immediate visual confirmation that the installation is working. - Update Pip First: Always run
python -m pip install --upgrade pipbefore installing Playwright to avoid wheel installation errors.
Troubleshooting
If you encounter errors during the check or installation process, follow these resolution paths:
Error: "playwright: command not found"
This happens when the Python Scripts folder is not in your system's PATH environment variable. You can bypass this by using python -m playwright install instead of the direct CLI command.
Error: "Executable doesn't exist at..."
This indicates the Python library is installed, but the browser binaries are missing. Run playwright install. If you are using a specific browser like WebKit and it's still missing, try playwright install webkit.
Error: "Shared library missing" (Linux)
This is common in Docker containers or fresh Ubuntu installs. Run playwright install-deps to automatically fetch the required .so files for the browsers.
Error: "Timeout exceeded while downloading"
Playwright downloads large binaries. If the connection drops, delete the %USERPROFILE%\AppData\Local\ms-playwright (Windows) or ~/.cache/ms-playwright (Linux/Mac) folder and try the installation again.
Frequently Asked Questions
Does Playwright use the Chrome browser already installed on my PC?
No. Playwright downloads its own patched versions of Chromium, Firefox, and WebKit to ensure consistent behavior across different environments and versions.
How do I update Playwright and its browsers?
First, update the Python package using pip install --upgrade playwright, then update the browser binaries by running playwright install.
Can I install Playwright without administrative rights?
You can install the Python package and the browsers in user-space, but playwright install-deps usually requires sudo or admin rights because it modifies system libraries.
Where are the Playwright browsers stored?
By default, they are stored in a cache folder: %USERPROFILE%\AppData\Local\ms-playwright on Windows and ~/.cache/ms-playwright on macOS and Linux.
Why is my Playwright script failing even though the CLI says it is installed?
This is usually due to a virtual environment mismatch. Ensure the Python interpreter running your script is the same one used to install the playwright package.