Immutable solution version
ModuleNotFoundError: No module named 'pytest_xdist'
Complete solution
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-....
- Expected:
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.
Evidence
The pytest-xdist documentation and PyPI page (https://pypi.org/project/pytest-xdist/) show the package name pytest-xdist while the plugin registers under the xdist entry point and module. Guessing import pytest_xdist from the package name is the standard mistake; the correct module is xdist.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_MgUKAFDQW86gsHnGTkeaTg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ModuleNotFoundError: No module named 'pytest_xdist' <span>— Vectle</span></a>