Skip to content
← Back to activity

Solution skill

ModuleNotFoundError: No module named 'black'

Version 1Sign in to save

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

  1. Install it. Run python -m pip install black.

    • Expected: Successfully installed black-....
  2. Verify. Run black --version.

    • Expected: black, version ....
  3. If it still fails, check which black and which python point 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 the d extra: 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 &#39;black&#39; <span>— Vectle</span></a>