Error Knowledge Base PIP DISTUTILS_UNINSTALL_BLOCKED

ERROR: Cannot uninstall '<pkg>'. It is a distutils installed project ...

pip refuses to uninstall a package that was installed via distutils/OS tooling without reliable metadata, because it can't safely determine which files to remove.

Affected versions: All pip versions that protect against partial uninstalls.

What This Error Means

pip refuses to uninstall a package that was installed via distutils/OS tooling without reliable metadata, because it can't safely determine which files to remove.

How to Fix It

  1. If the package is system-owned, uninstall it via your OS package manager instead of pip.
  2. If the package is project dependency, create a clean venv, install there, and stop modifying system Python.
  3. If you need to keep the environment but clean it, consider rebuilding the environment rather than trying to surgically uninstall distutils-era packages.

Why It Happens

  • The package was installed by a system package manager or another installer that didn't create pip-managed metadata.
  • The package metadata is incomplete or corrupted.
  • You're attempting to use pip to manage system Python packages.

How to Verify

  1. After uninstalling via the correct manager, run python -m pip show <pkg> and confirm it's gone.
  2. Run python -m pip check to confirm no broken dependencies remain.

Manual ownership checks

  1. Check where the package lives: python -m pip show <pkg> (Location).
  2. Decide whether the package is system-managed or project-managed (venv).
  3. If you need to remove it from system Python, use the system package manager.

Common CLI Output

ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Why distutils installs are hard to uninstall

  1. pip prefers dist-info metadata that records installed files and versions.
  2. distutils-era installs can lack complete metadata, making it risky to uninstall without leaving orphan files or removing unrelated files.
  3. pip blocks the uninstall rather than performing a potentially destructive partial uninstall.

Prevention Tips

  • Avoid installing project dependencies into system Python.
  • Use venvs and dependency lock files to keep environments reproducible.
  • Avoid mixing package managers within the same environment.

Where This Can Be Triggered

github.com/pypa/pip/blob/25.3/src/pip/_internal/exceptions.py

pip blocks uninstalls when it detects a distutils-era install without reliable metadata, it raises LegacyDistutilsInstall rather than risk a partial uninstall. - GitHub

class LegacyDistutilsInstall(DiagnosticPipError):
    reference = "uninstall-distutils-installed-package"

    def __init__(self, *, distribution: BaseDistribution) -> None:
        super().__init__(
            message=Text(f"Cannot uninstall {distribution}"),
            context=(
                "It is a distutils installed project and thus we cannot accurately "
                "determine which files belong to it which would lead to only a partial "
                "uninstall."
            ),
            hint_stmt=None,
        )

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list