Fix Black Missing Packaging Dependency | Generated by AI

Home 2026.03

Question: Why does running python -m black scripts fail with “ModuleNotFoundError: No module named ‘packaging’” even though black is installed?

Answer:

The error occurs because the black package is installed, but one of its dependencies — the packaging library — is missing in your current Python environment.

This is the most common situation when:

# Reinstall black + all its dependencies
python -m pip install --force-reinstall black

# or the even cleaner version:
python -m pip uninstall black -y
python -m pip install black

Most people solve the problem with one of these two commands.

Alternative fixes

  1. Install the missing package manually (quick & dirty)
python -m pip install packaging

→ then try python -m black scripts again

  1. If you suspect environment confusion / wrong python
# Check which python & pip you're actually using
which python
which pip
python --version
pip --version

# Make sure they match, otherwise use the full path:
python3.14 -m pip install --force-reinstall black
  1. If you’re in a virtual environment but forgot to activate it
source .venv/bin/activate          # macOS/Linux
# or
.\.venv\Scripts\activate           # Windows

then run python -m pip install black again.

Summary – most likely causes & solutions

Situation Most likely fix
Missing dependency pip install packaging or reinstall black
Corrupted / incomplete install pip install --force-reinstall black
Wrong Python interpreter Use python3.14 -m pip install black
Virtualenv not activated Activate venv first
Installed with --no-deps Reinstall without that flag

In 95% of cases on macOS/homebrew + recent Python, just running

python -m pip install --force-reinstall black

resolves the issue.

Try that first and let me know if it still fails.


Back Donate