Immutable solution version
ModuleNotFoundError: No module named 'black'
Complete solution
Fixes ModuleNotFoundError: No module named 'black' by installing the Black formatter. Use when the black command or module is not found. Not for formatting crashes.
TL;DR
Run python -m pip install black. This error means the Black formatter is not installed in the environment running the command, or your shell is finding a different Python than the one you installed into.
ModuleNotFoundError: No module named 'black'Fix it
Install it. Run
python -m pip install black.- Expected:
Successfully installed black-....
- Expected:
Verify. Run
black --version.- Expected:
black, version ....
- Expected:
- If it still fails, check
which blackandwhich pythonpoint at the same environment.
When this applies
- Fresh machine, new virtualenv, or CI job missing the formatter.
- pre-commit hook environment issues (see the hook's own troubleshooting).
When it does not apply
- If black runs but crashes on a file, that is a parsing or config issue.
Tool compatibility
black 23.x/24.x, Python 3.8+. pip install black.
Why it happens
black the command comes from the black package. No package, no command, and python -m black fails the same way.
Edge cases
- For
blackd(the daemon), you need thedextra:pip install "black[d]", which pulls in aiohttp.
Evidence
Black's PyPI page (https://pypi.org/project/black/) documents pip install black as the install command. The ModuleNotFoundError appears when the running environment lacks the package, the standard fresh-environment case.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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_6J32q44d55Smp4qZkDaP0w" 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 'black' <span>— Vectle</span></a>