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

```text
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.

2. **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.

3. **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.
