Error Knowledge Base PIP PERMISSION_DENIED

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied

pip tried to write into a directory you don't have permission to modify (often system site-packages or a protected install directory).

Affected versions: All pip versions.

What This Error Means

pip tried to write into a directory you don't have permission to modify (often system site-packages or a protected install directory).

How to Fix It

  1. Preferred: install into a virtual environment and run pip from there.
  2. If a venv isn't possible, use a user install when supported/appropriate: python -m pip install --user <package>.
  3. Avoid sudo pip ... unless you're intentionally managing a system Python and understand the risks.
  4. Fix ownership/permissions if they were broken by running pip as a different user.

Why It Happens

  • You're installing into a system Python directory without root/admin privileges.
  • You activated the wrong environment (or didn't activate a venv).
  • A directory is owned by another user (common after using sudo pip ...).
  • On Windows, the target file is locked or the directory is protected.

How to Verify

  1. Re-run the pip install and confirm it completes without permission errors.
  2. Run python -m pip show <package> to confirm the package is installed in the expected environment.

Manual install target checks

  1. Check where pip would install: python -m pip --version (shows python path) and python -c 'import site; print(site.getsitepackages())'.
  2. Confirm you're in the intended environment (venv/conda/system).
  3. On Windows, close IDEs/terminals that might be using the Python install and retry.

Common CLI Output

ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/locale'
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'c:\\python311\\scripts\\pip.exe'

Where pip installs packages

  1. pip installs packages into the active Python environment's site-packages (or another target specified by flags).
  2. If you're installing into a system Python location without appropriate permissions, writes fail with permission errors.
  3. On Windows, access denied can also occur if files are locked by another process.

Prevention Tips

  • Use venvs for all projects and CI jobs.
  • Don't mix sudo and non-sudo installs into the same environment.
  • Keep system Python package management separate from project dependencies.

Where This Can Be Triggered

github.com/pypa/pip/blob/25.3/src/pip/_internal/commands/install.py

pip formats permission-related install failures in create_os_error_message() and adds an --user/permissions hint when errno is EACCES. - GitHub

def create_os_error_message(
    error: OSError, show_traceback: bool, using_user_site: bool
) -> str:
    """Format an error message for an OSError

    It may occur anytime during the execution of the install command.
    """
    parts = []

    # Mention the error if we are not going to show a traceback
    parts.append("Could not install packages due to an OSError")
    if not show_traceback:
        parts.append(": ")
        parts.append(str(error))
    else:
        parts.append(".")

    # Spilt the error indication from a helper message (if any)
    parts[-1] += "\n"

    # Suggest useful actions to the user:
    #  (1) using user site-packages or (2) verifying the permissions
    if error.errno == errno.EACCES:
        user_option_part = "Consider using the `--user` option"
        permissions_part = "Check the permissions"

        if not running_under_virtualenv() and not using_user_site:
            parts.extend(
                [
                    user_option_part,
                    " or ",
                    permissions_part.lower(),
                ]
            )
        else:
            parts.append(permissions_part)
        parts.append(".\n")

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

Join our mailing list