python
system_error
ai_generated
true
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/local/lib/python3.9/site-packages/package'
ID: python/pip-install-error-permission-denied
80%Fix Rate
87%Confidence
0Evidence
2024-08-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
pip lacks write permissions to the target site-packages directory, typically because it is owned by root or another user.
generic中文
pip 缺少对目标 site-packages 目录的写入权限,通常是因为该目录属于 root 或其他用户。
Workarounds
-
90% success
pip install --user package
-
98% success
python3 -m venv myenv && source myenv/bin/activate && pip install package
-
70% success
sudo chown -R $USER /usr/local/lib/python3.9/site-packages
Dead Ends
Common approaches that don't work:
-
50% fail
This can work but may cause permission issues later and is not recommended for user environments.
-
95% fail
Reinstalling Python does not change directory ownership.
-
40% fail
This may work but can lead to conflicts with system packages.