ModuleNotFoundError: No module named 'win32api'
Fixes Scrapy failing on Windows because the pywin32 package is missing. Use when `import scrapy` or `scrapy crawl` raises ModuleNotFoundError naming win32api on Windows. Not for missing twisted or missing scrapy itself.
On Windows, Scrapy (via Twisted) needs the pywin32 package, which provides the win32api module. Install it with python -m pip install pywin32 and the import works. This is Windows-only; you will never see this error on macOS or Linux.
The error
ModuleNotFoundError: No module named 'win32api'Fix it
- Install pywin32
python -m pip install pywin32Expected: Successfully installed pywin32-....
- Confirm the import chain
python -c "import win32api; import scrapy; print('ok')"Expected: prints ok.
- Run your spider
scrapy crawl [spider-name]Expected: the crawl starts instead of dying at import.
When this applies
- you are on Windows and Scrapy fails naming
win32api - the traceback goes through twisted's Windows support modules
- a fresh Windows venv or CI runner
When it does NOT apply
- macOS or Linux will never produce this error; look at the real missing module instead
No module named 'twisted'is the separate Twisted gap
Compatibility
All Scrapy 2.x on Windows, all CPython versions with pywin32 wheels. The Scrapy docs FAQ lists pywin32 as a Windows requirement.
Why it happens
Twisted's Windows reactor imports win32api for process and handle management, and pywin32 is the package that provides it. It is a platform-specific dependency, so pip's generic dependency resolution does not always pull it in, and minimal Windows installs miss it.
Edge cases
- After installing pywin32, some setups need the post-install step (
python Scripts/pywin32_postinstall.py -install) for the COM bits. The win32api import itself works without it. - If you use conda on Windows,
conda install pywin32is the equivalent. - Anaconda on Windows usually ships pywin32 already, so this mostly bites plain python.org installs and fresh venvs.
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.