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.
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.
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txtOr use a user install
When a venv is not an option, --user targets a per-user location the job can write to.
pip install --user -r requirements.txtHow 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.