How to fix ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages' in Python

PythonBEGINNERMEDIUMUpdated Dec 7, 2025· 300 views

When running pip install without a virtual environment, you may encounter a Permission denied error trying to write to /usr/lib/python3/dist-packages. This happens when pip tries to install to the system-wide Python directory without proper permissions.

Quick fix

Fixes EACCES

# Create a virtual environment
python3 -m venv myenv

# Activate it on Linux/macOS
source myenv/bin/activate

# On Windows
myenv\Scripts\activate

# Now pip will install to your local environment
pip install your-package-name
  1. Create and activate a Python virtual environment
  2. Use pip install with the --user flag for user-level installation
  3. Check your current Python and pip setup
  4. Use a Python version manager (pyenv) for better flexibility
python — error
# Create a virtual environment
python3 -m venv myenv
# Activate it on Linux/macOS
source myenv/bin/activate
# On Windows
myenv\Scripts\activate
# Now pip will install to your local environment
pip install your-package-name
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages'

What this error means

This error occurs when pip attempts to install a Python package to the system-wide site-packages directory (typically /usr/lib/python3.x/dist-packages or /usr/lib/python3.x/site-packages), but the current user does not have write permissions to that location. The system-wide Python installation is protected to prevent accidental corruption of your operating system's Python environment, which many system tools depend on. The [Errno 13] is the POSIX permission denied error code. Pip attempts to write package files to the site-packages directory during installation, and when it lacks the necessary permissions, the installation fails.

Typical symptoms

  • pip install commands fail with "Permission denied" error messages
  • Error messages reference /usr/lib/python3 or /usr/lib/python2 directories
  • Installation works with sudo pip install but not with regular pip
  • Error occurs when installing to system-wide Python, not in a virtual environment
  • The error typically includes "[Errno 13]" in the message
  • Commands like pip install package-name fail silently with no output

Common causes

  1. User does not have write permissions to the system-wide site-packages directory (most common)
  2. Running pip without a virtual environment on a system where Python was installed as root
  3. System-wide Python installation is protected by the OS or system administrator
  4. Using system package manager-installed Python (apt, yum, brew) without proper user-level setup
  5. Incorrect file permissions on the Python installation directory
  6. SELinux or AppArmor policies restricting write access to system directories
  7. Multi-user system where each user should have isolated Python environments

How to fix "ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages'"

1Create and activate a Python virtual environment

The recommended solution is to use a virtual environment, which creates an isolated Python installation in your home directory where you have full permissions:

bash
# Create a virtual environment
python3 -m venv myenv

# Activate it on Linux/macOS
source myenv/bin/activate

# On Windows
myenv\Scripts\activate

# Now pip will install to your local environment
pip install your-package-name

This approach is preferred because it:
- Isolates project dependencies
- Avoids system-wide pollution
- Works without elevated permissions
- Allows different projects to use different package versions

2Use pip install with the --user flag for user-level installation

If you don't want to use a virtual environment, you can install packages to your user home directory:

bash
pip install --user package-name

This installs packages to ~/.local/lib/pythonX.Y/site-packages instead of the system directory. You have full write permissions to your home directory. To verify this worked:

bash
pip list --user
3Check your current Python and pip setup

Identify which Python and pip you're using to understand the issue better:

bash
# Show which pip executable is being used
which pip
which pip3

# Show the Python version and installation location
python3 --version
python3 -c "import sys; print(sys.prefix)"

# List where pip would install packages
pip show -f pip

If the output shows /usr/lib or /usr paths, you're using the system Python. Consider using a virtual environment or Python version manager instead.

4Use a Python version manager (pyenv) for better flexibility

For a more professional setup, use pyenv to install Python in your home directory:

bash
# Install pyenv (on macOS with homebrew)
brew install pyenv

# On Linux, follow: https://github.com/pyenv/pyenv#installation

# Install a specific Python version
pyenv install 3.11.0

# Set it as your local or global Python
pyenv local 3.11.0
pyenv global 3.11.0

# Now pip will use your user-owned Python
pip install package-name

This approach gives you:
- Complete control over Python versions
- Per-project Python version selection
- No permission issues
- Easy switching between versions

5Verify permissions if you must use system Python (not recommended)

If you have system access and need to allow your user to install packages system-wide (not recommended for security reasons), you can check and fix permissions:

bash
# Check current permissions on site-packages
ls -ld /usr/lib/python3/dist-packages

# See which group owns the directory
stat /usr/lib/python3/dist-packages

# If your user should have access, you might add them to a group
# This is a system administration task and varies by distribution
sudo usermod -a -G python-group $USER

IMPORTANT: Modifying system Python permissions can break system tools that depend on it. Only do this if you fully understand the implications.

6Never use sudo with pip (unless absolutely unavoidable)

While it might seem like using sudo pip install will solve the problem, this creates serious issues:

bash
# DON'T do this:
sudo pip install package-name  # ❌ BAD

# WHY it's bad:
# - Installs packages as root, creating permission mismatches
# - Can break system tools that depend on system Python
# - Can corrupt your Python installation
# - Mixes your user code with system code

If you're tempted to use sudo, it's a sign you should use a virtual environment or --user flag instead. The only legitimate case for sudo with pip is system administration on a clean system Python installation.

Advanced notes

Modern Python best practices strongly discourage system-wide package installation. PEP 668 (https://peps.python.org/pep-0668/) formalizes the principle that system-provided Python should not be modified with pip, to prevent conflicts with the system package manager. Some Linux distributions (Debian, Ubuntu, Fedora) now enforce this with a EXTERNALLY-MANAGED environment marker, forcing users to use virtual environments or the --user flag. When working with multiple Python versions or complex dependency trees, consider using tools like Poetry or pdm which manage virtual environments automatically and lock dependencies for reproducibility. For CI/CD pipelines, always use virtual environments in your deployment scripts to ensure consistency across environments.

Frequently asked questions

What does "EACCES" mean?
x/site-packages), but the current user does not have write permissions to that location. The system-wide Python installation is protected to prevent accidental corruption of your operating system's Python environment, which many system tools depend on. The [Errno 13] is the POSIX permission denied error code.
How do I fix "EACCES"?
When running pip install without a virtual environment, you may encounter a Permission denied error trying to write to /usr/lib/python3/dist-packages. This happens when pip tries to install to the system-wide Python directory without proper permissions.
What causes "EACCES"?
User does not have write permissions to the system-wide site-packages directory (most common) Running pip without a virtual environment on a system where Python was installed as root System-wide Python installation is protected by the OS or system administrator
Is the "EACCES" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading