2025, Nov 07 05:00

Fix PermissionError: [Errno 13] Permission denied when uninstalling pdfminer.six in /usr/lib/python3/dist-packages with pip or apt

Getting PermissionError [Errno 13] uninstalling pdfminer.six? Learn why /usr/lib system installs fail and how to remove them safely with apt or sudo pip.

Uninstalling a Python package should be straightforward, but if you see PermissionError: [Errno 13] Permission denied while removing something like pdfminer.six, you’re likely dealing with a system-level install living under /usr/lib/python3/dist-packages/. This guide walks through why that happens and how to cleanly remove the package without breaking anything.

Reproducing the issue

Here’s what the typical failure looks like when attempting to uninstall pdfminer.six directly with pip:

pip uninstall pdfminer.six
Found existing installation: pdfminer.six -VERSION-
Uninstalling pdfminer.six--VERSION-:
  Would remove:
    /usr/lib/python3/dist-packages/pdfminer
    /usr/lib/python3/dist-packages/pdfminer.six-_VERSION_.egg-info
Proceed (Y/n)? Y
ERROR: Exception:
Traceback (most recent call last):
  ...
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/pdfminer' -> '/tmp/pip-uninstall-xxxxxxx'

In similar situations with other PDF-related packages (for example, ocrmypdf or pikepdf), the error manifests the same way; only the file name mentioned at the end differs.

PermissionError: [Errno 13] Permission denied

What’s actually going on

The key signal is the installation path: /usr/lib/python3/dist-packages/. Anything under this directory is installed at the system level. Such packages arrive either through the system package manager (apt/apt-get/etc) or through pip executed with elevated privileges. Regardless of which tool put the files there, removing them requires root access. When pip runs without sufficient permissions, it cannot move or delete those files, and the uninstall fails with PermissionError.

How to remove the package correctly

First, match the uninstall tool to how the package was installed. For a system package manager install, the package name differs from its Python import name. In this case, the apt package name is python3-pdfminer, not pdfminer.six. For a system-level pip install, you must run pip with root privileges to allow it to remove files from /usr/lib/python3/dist-packages/.

Use one of the following, depending on the origin of the install:

sudo apt remove python3-pdfminer
sudo pip uninstall pdfminer.six

If you’re unsure which path to take, a quick way to verify whether the system package manager knows about it is to search for the package by name and look for it in the results.

Why this matters

System-level and user-level Python environments obey different ownership and permission rules. Mixing them leads to confusing outcomes, like pip failing to remove files managed by your OS, or the inverse. Understanding the installation path and the tool that owns the files helps you avoid permission errors and keeps your Python stack consistent.

Takeaways

If a package resides in /usr/lib/python3/dist-packages/, treat it as a system-level install. Use the right tool and the correct package name when uninstalling: python3-pdfminer for apt, pdfminer.six for pip. If pip warns about running as root, that’s expected when dealing with system-owned files; the point is to align the tool and privileges with how the package was installed. For day-to-day development, consider isolating dependencies in a virtual environment to avoid crossing streams between system and project environments.

The article is based on a question from StackOverflow by va pupa and an answer by phd.