ModuleNotFoundError: No module named 'pytest_xdist'
Fixes ModuleNotFoundError: No module named 'pytest_xdist' by importing xdist, the real module name. Use when code guesses the import from the PyPI name. Not for a genuinely missing install.
TL;DR
Import xdist, not pytest_xdist. The package is called pytest-xdist on PyPI but the importable module is just xdist. If you actually need the plugin, pip install pytest-xdist is the fix.
ModuleNotFoundError: No module named 'pytest_xdist'Fix it
- Fix the import. Change
import pytest_xdisttoimport xdist.
- Expected: the import succeeds (if pytest-xdist is installed).
- If it still fails, install the package:
python -m pip install pytest-xdist.
- Expected:
Successfully installed pytest-xdist-....
When this applies
- You guessed the module name from the PyPI package name.
- Code or docs you copied use the wrong import.
When it does not apply
- If
import xdistalso fails, the package is genuinely not installed.
Tool compatibility
pytest-xdist 2.x/3.x. The module has always been xdist.
Why it happens
PyPI package names and import names often differ. The pytest- prefix is a naming convention for plugins; the module drops it.
Edge cases
- Same trap as
pytest-cov(modulepytest_cov, which keeps the prefix) versuspytest-xdist(modulexdist, which drops it). Check each plugin's docs.
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.