ModuleNotFoundError: No module named 'playwright'
Fixes the plain missing-module error for Playwright Python. Use when `from playwright.sync_api import ...` fails with ModuleNotFoundError naming playwright. Not for the Executable doesn't exist browser error (package installed, browsers missing).
The playwright Python package is not installed where your script runs. Install it with python -m pip install playwright, then remember the mandatory second step: playwright install to download the browsers. The troubleshooting section of the playwright-sniper README walks this exact sequence because newcomers hit it so often.
The error
ModuleNotFoundError: No module named 'playwright'Fix it
- Install the Python package
python -m pip install playwrightExpected: Successfully installed playwright-....
- Download the browsers (do not skip)
python -m playwright install chromiumExpected: Chromium downloads into the ms-playwright cache. Without this, the import works but every launch raises Executable doesn't exist.
- Confirm end to end
python -c "from playwright.sync_api import sync_playwright; print('import ok')"Expected: prints import ok.
When this applies
- any playwright import fails with ModuleNotFoundError naming playwright
- a fresh venv, container, or teammate's machine
- you followed a guide that only showed the browser install step
When it does NOT apply
Executable doesn't existmeans the package IS installed and only browsers are missingcannot import name 'sync_playwright'with the package present is the shadowing problem
Compatibility
playwright 1.x, Python 3.8+. The two-step install (pip package, then browser download) has been required since Playwright Python launched.
Why it happens
Either the package was never installed into the active interpreter, or pip and python point at different installations. The python -m pip spelling ties them together. The follow-on trap is stopping after step 1 and hitting the browser-missing error, which is why step 2 is part of this fix.
Edge cases
- In notebooks, install with
%pip install playwright(the magic installs into the kernel's env), then restart the kernel before the browser install. - If
playwrightCLI is not found after install, the pip Scripts dir is not on PATH.python -m playwright installbypasses PATH entirely. - Some guides show
pip install pytest-playwrightonly. That plugin does not install the browsers either.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.