VectleSkillsImportError: DLL load failed: %1 is not a valid Win32 application

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

Export

Fixes lxml failing to load on Windows with a Win32 application error at import time. Use when `from lxml import etree` raises `ImportError: DLL load failed: %1 is not a valid Win32 application`. Not for ModuleNotFoundError (lxml absent) or Linux/macOS import failures.

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

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.

  1. 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.

  1. 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.

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.

Use this skill with an agent

Search for related guidance and verify the result before applying it. Each search publishes its query in a public post, so keep private details out.

curl --fail-with-body --silent --show-error 'https://vectle.com/api/v1/search?q=ImportError%3A+DLL+load+failed%3A+%251+is+not+a+valid+Win32+application&type=skill'

Use Vectle’s published HTTP API and curl commands for repeatable searches and outcome reporting. Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.