VectleSkillsImportError: cannot import name 'sync_playwright' from 'playwright'

ImportError: cannot import name 'sync_playwright' from 'playwright'

Export

Fixes the Playwright import failure where the package imports but has no sync_playwright inside. Use when `from playwright.sync_api import sync_playwright` raises ImportError naming sync_playwright. Not for `No module named 'playwright'` or the browser Executable doesn't exist error.

Nine times out of ten you have a file named playwright.py in your working directory shadowing the real package. Rename it (and clear __pycache__) and the import works. If there is no such file, the install is broken: python -m pip install --force-reinstall playwright restores the missing names.

The error

ImportError: cannot import name 'sync_playwright' from 'playwright'

Fix it

  1. Check what got imported as playwright
python -c "import playwright; print(playwright.__file__)"

Expected: a site-packages path ending in playwright/__init__.py. A path in your project ending in playwright.py is the shadowing file.

  1. Rename the shadowing file

Rename your playwright.py to something like playwright_demo.py, delete the __pycache__ folder next to it, then:

python -c "from playwright.sync_api import sync_playwright; print('ok')"

Expected: prints ok. The script directory beats site-packages in import order, so your file always won.

  1. If nothing shadows it, reinstall
python -m pip install --force-reinstall playwright

Expected: the import from step 2 now works. A partial install can leave a playwright directory without the sync_api subpackage.

When this applies

  • from playwright.sync_api import sync_playwright (or async_api) raises ImportError naming the function
  • your script sits next to a file called playwright.py
  • the import works everywhere except your project folder

When it does NOT apply

  • ModuleNotFoundError: No module named 'playwright' means nothing installed
  • Executable doesn't exist happens later, at browser launch
  • cannot import name 'stealth_sync' from 'playwright_stealth' is the separate stealth package

Compatibility

playwright 1.x Python, all versions. The shadowing trap is pure import semantics and version-independent.

Variant phrasings

ImportError: cannot import name 'async_playwright' from 'playwright'

The async twin. Same cause, same fix.

ImportError: cannot import name 'sync_playwright' from 'playwright' (unknown location)

The (unknown location) suffix means Python found a namespace package with no code, typical of a broken or namespace-shadowed install. Reinstall per step 3.

Why it happens

Python imports from the script's directory before site-packages. A file named playwright.py next to your script becomes the playwright module, and it naturally contains no sync_playwright. The less common variant is a genuinely broken install where the sync_api subpackage is missing from site-packages.

Edge cases

  • Check for playwright/ directories too, not just playwright.py. A stray folder shadows the same way.
  • In notebooks, the kernel's working directory matters, not the notebook's folder. os.getcwd() tells you where to look.
  • If you installed with pip install playwright while a conda env was active but run the script with system Python, that is the two-interpreter problem, not shadowing.

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.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=ImportError%3A+cannot+import+name+%27sync_playwright%27+from+%27playwright%27&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.