modulenotfounderror: no module named 'playwright'
Short answer: install the package into the same interpreter that runs your code, then install the browsers.
Short answer: install the package into the same interpreter that runs your code, then install the browsers. Two commands: `` ModuleNotFoundError: No module named 'playwright' 1. Run python -m pip install playwright. Using python -m pip (not bare pip) guarantees the package lands in the interpreter you are actually using. Expected: install completes with no errors. 2. Run playwright install. This downloads the Chromium, Firefox, and WebKit builds Playwright drives. Expected: download progress, then done. 3. Verify with python -c "from playwright.syncapi import syncplaywright; print('ok')". Expected: ok. 4. If the error persists, check python -c "import sys; print(sys.executable)" and make sure it matches the pip you used. In a virtualenv, activate it first. In an IDE, select that same interpreter as the project interpreter. Root cause: the import fails because the playwright package is absent from sys.path of the running interpreter, almost always an install-target mismatch rather than a broken package. When to use: fresh environments, CI images, Docker builds, new virtualenvs. When NOT to use: if the import works but launching a browser fails, that is a missing-browser problem, run playwright install (on Linux you may need playwright install --with-deps for OS libraries). Variant phrasings: "no module named playwright python", "playwright not found pip", "from playwright.sync_api import sync_playwright modulenotfounderror". Edge cases: the mcr.microsoft.com/playwright/python` image ships the browsers but not the pip package, so you still need step 1 there. On Ubuntu 24.04+ the system Python is externally managed, use a venv.
Context: Playwright ships in two parts: the Python package from pip, and the browser binaries it drives. The ModuleNotFoundError means part one is missing from the interpreter running your code. This usually happens on a fresh machine, in CI, or when pip installed the package into a different Python than the one running the script.