Skip to content
Latchkey

pip "OSError: [Errno 13] Permission denied" Installing in CI

pip downloaded fine but could not write the files: the target site-packages belongs to root (or another user) and the job is not running as that user. This is a filesystem permission problem, not a packaging one.

What this error means

pip resolves and downloads, then fails at the install step with [Errno 13] Permission denied on a path under site-packages. It is reproducible - the same command fails the same way until permissions or the target change.

pip output
ERROR: Could not install packages due to an OSError: [Errno 13]
Permission denied: '/usr/local/lib/python3.12/site-packages/certifi'
Consider using the `--user` option or check the permissions.

Common causes

System site-packages owned by root

On an image where the global interpreter’s site-packages is root-owned, a non-root job user cannot write to it, so the install aborts.

No virtualenv in use

Installing into the global Python instead of a venv forces pip to write to a privileged location. A venv the job owns sidesteps the whole issue.

How to fix it

Install into a virtualenv you own

A venv created by the job user is writable by it, so no privilege is needed.

Terminal
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

Or use a user install

When a venv is not an option, --user targets a per-user location the job can write to.

Terminal
pip install --user -r requirements.txt

How to prevent it

  • Always install into a venv the job user owns.
  • Avoid sudo pip - it creates root-owned files that break later non-root installs.
  • Match the container user to the owner of the target site-packages.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →