On Windows this means the lxml binary does not match your Python: a 32-bit wheel under 64-bit Python, or a corrupted download. Reinstall cleanly with `pip uninstall lxml -y` then `pip install --only-binary :all: lxml`, and make sure the Python bitness matches the wheel pip picked. The import works immediately after a matching wheel lands.

## The error

```text
ImportError: DLL load failed: %1 is not a valid Win32 application
```

## Fix it

1. **Confirm your Python's bitness**

```
python -c "import struct; print(struct.calcsize('P') * 8)"
```
Expected: prints `64` on 64-bit Python or `32` on 32-bit Python. Write the number down.

2. **Reinstall lxml from a binary wheel only**

```
pip uninstall lxml -y
pip install --only-binary :all: lxml
```
Expected: pip downloads a wheel whose filename contains `win_amd64` for 64-bit Python or `win32` for 32-bit Python, matching step 1.

3. **Confirm the import**

```
python -c "from lxml import etree; print('ok')"
```
Expected: prints `ok` with no DLL error.

## When this applies

- the full text is `ImportError: DLL load failed: %1 is not a valid Win32 application` on `from lxml import etree`
- you are on Windows and recently switched Python versions or bitness
- the error appeared right after a pip install or upgrade of lxml

## When it does NOT apply

- ModuleNotFoundError means lxml is not installed at all
- `DLL load failed: The specified module could not be found` is a different message (missing VC++ redist or dependency DLLs)
- Linux/macOS `Symbol not found` errors are the Unix cousin, different fix

## Compatibility

lxml 4.x/5.x on Windows, CPython 3.8+. The `%1` phrasing is Windows-specific and comes from the OS loader.

## Variant phrasings

### `ImportError: DLL load failed while importing etree: %1 is not a valid Win32 application`

Newer Python versions name the module being imported (`while importing etree`). Same cause, same fix.

## Why it happens

lxml ships compiled C extensions, and Windows is strict about binary compatibility. If pip installs a 32-bit (`win32`) wheel into a 64-bit Python, or a wheel file gets truncated mid-download, the OS loader refuses the DLL and Python reports `%1 is not a valid Win32 application`. The `%1` is the loader's placeholder for the DLL path.

## Edge cases

- If you must support 32-bit Python, keep it, but install the `win32` wheel deliberately. Do not mix.
- A stale `lxml` directory left in site-packages by a manual copy can shadow the wheel. Uninstall first (step 2 does this).
- If the error persists after a clean wheel install, check for conflicting `libxml2.dll` copies on PATH from other software. The wheel's bundled DLLs normally win, but a PATH entry can interfere.
