ModuleNotFoundError: No module named 'twisted'
Fixes Scrapy failing at import because its Twisted dependency is missing. Use when `import scrapy` raises ModuleNotFoundError naming twisted. Not for missing scrapy itself or missing win32api on Windows.
Scrapy is built on Twisted for its async networking, and if Twisted is not installed Scrapy cannot even import. Run python -m pip install twisted (or just reinstall Scrapy with python -m pip install --force-reinstall scrapy, which pulls Twisted back in). import scrapy then works.
The error
ModuleNotFoundError: No module named 'twisted'Fix it
- Install Twisted into the running environment
python -m pip install twistedExpected: Successfully installed twisted-....
- Confirm the Scrapy import
python -c "import scrapy; print(scrapy.__version__)"Expected: prints the Scrapy version with no ModuleNotFoundError.
- If it still fails, reinstall Scrapy so its dependency set is complete
python -m pip install --force-reinstall scrapyExpected: pip reinstalls scrapy and all of its declared dependencies, including twisted.
When this applies
import scrapyorscrapy crawlfails namingtwisted- Twisted was uninstalled or never pulled in by a partial install
- a minimal Docker image or venv where only some requirements got installed
When it does NOT apply
No module named 'scrapy'means Scrapy itself is missingNo module named 'win32api'is the Windows pywin32 gap- Twisted installs fine but
scrapystill fails on something else
Compatibility
All Scrapy 2.x versions depend on Twisted. Twisted publishes wheels for CPython 3.8+ on Windows, macOS, and Linux.
Why it happens
Scrapy does import twisted (via twisted.internet) at module import time, not lazily. Dependency resolvers normally install Twisted alongside Scrapy, but a --no-deps install, a botched uninstall, or a requirements file that lists scrapy without letting pip resolve dependencies can leave Twisted out while Scrapy itself is present.
Edge cases
- If you installed with
pip install --no-deps scrapy, reinstall normally. The --no-deps flag is the usual culprit. - Twisted on Windows needs the Visual C++ build tools only for source builds; wheels make this a non-issue on supported Pythons.
- After installing, run
scrapy version(not just the import) to confirm the CLI entry point works too.
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.