High severity beginner · Fix: 2-5 min

ModuleNotFoundError

ModuleNotFoundError: No module named 'playwright'

What this error means
This error occurs when the Python playwright package is not installed but your code tries to import or use it for browser automation.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 3, in <module>
    from playwright.sync_api import sync_playwright
ModuleNotFoundError: No module named 'playwright'
QUICK FIX
Install playwright with 'pip install playwright' and run 'playwright install' to set up browser binaries.

Why it happens

The error happens because the playwright package is missing from your Python environment. Your code attempts to import playwright modules, but Python cannot find the package since it was never installed or the environment is incorrect.

Detection

You can detect this error early by running 'pip show playwright' or checking your environment's installed packages before running your script.

Causes & fixes

1

playwright package is not installed in the current Python environment

✓ Fix

Run 'pip install playwright' in your environment to install the package before running your code.

2

Running the script in a different environment where playwright is not installed

✓ Fix

Activate the correct virtual environment or container where playwright is installed before executing the script.

3

playwright installed but not properly initialized with 'playwright install' command

✓ Fix

After installing the package, run 'playwright install' to download browser binaries required for automation.

Code: broken vs fixed

Broken - triggers the error
python
from playwright.sync_api import sync_playwright  # This line triggers ModuleNotFoundError if playwright is missing

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto('https://example.com')
    print(page.title())
    browser.close()
Fixed - works correctly
python
import os
from playwright.sync_api import sync_playwright  # Fixed: playwright installed and imported properly

# Ensure environment is set up with playwright installed
with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto('https://example.com')
    print(page.title())
    browser.close()
Installed the playwright package and imported sync_playwright correctly so the module is found and usable.

Workaround

If you cannot install playwright immediately, catch the ModuleNotFoundError and provide a user-friendly message prompting installation.

Prevention

Use virtual environments and dependency management tools like requirements.txt or poetry.lock to ensure playwright is installed and consistent across deployments.

Python 3.7+ · playwright >=1.0.0 · tested on 1.35.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.