How to fix ERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/usr/lib/python3/dist-packages' in Python
When installing Python packages, you may encounter an OSError [Errno 30] indicating the site-packages directory or Python installation path is read-only. This typically occurs in restricted environments like ChromeOS, containerized systems, or when the filesystem is mounted as read-only.
Quick fix
Fixes EROFS
pip install --user package-name- Use pip install with --user flag for user-level installation
- Create and use a Python virtual environment
- Check filesystem mount status and permissions
- Use Docker volume mounts correctly (if using containers)
pip install --user package-nameERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/usr/lib/python3/dist-packages'
What this error means
The "OSError: [Errno 30] Read-only file system" error occurs when pip attempts to write package files to a directory that has been mounted or configured as read-only. This prevents pip from modifying, creating, or installing any files in that location. The error code EROFS (Error Read-Only FileSystem) indicates the underlying filesystem itself is mounted as read-only, which is a system-level restriction that pip cannot bypass. This commonly occurs in restricted environments, containerized systems, ChromeOS, shared network drives, or backup/archive systems where the filesystem is intentionally protected from modification.
Typical symptoms
- pip install commands fail with "Read-only file system" error message
- Error messages include "[Errno 30]" and reference site-packages directory
- Error appears when trying to install packages to system-wide Python
- Installation may succeed with --user flag but fails for system-wide paths
- Error may appear in containerized environments or cloud shells
- Commands execute with appropriate permissions but still fail
- The error references paths like /usr/lib/python3 or /opt/python
Common causes
- The site-packages directory or Python installation path is mounted as read-only (most common)
- Running pip in a restricted environment like ChromeOS or containerized systems
- Filesystem is mounted read-only due to system configuration or system administrator policy
- Working in a shared network drive or network filesystem mounted read-only
- Storage device has failed or filesystem is corrupted and automatically mounted read-only
- Running in a Docker container without proper volume permissions
- Backup or archival filesystem that intentionally prevents modifications
- SELinux or AppArmor policies restricting write access to filesystem
How to fix "ERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/usr/lib/python3/dist-packages'"
When the system-wide site-packages is read-only, install packages to your user home directory instead:
pip install --user package-nameThis installs to ~/.local/lib/pythonX.Y/site-packages where you typically have write permissions:
# Verify the package was installed for user
pip list --user
# Show where user packages are installed
python -m siteThis is the most straightforward solution when working in restricted environments. Your packages will be available when you run Python, but they're isolated to your user account.
The recommended approach is to use a virtual environment, which creates a writable directory in your home space:
# Create a virtual environment
python3 -m venv myenv
# Activate it
source myenv/bin/activate # On Linux/macOS
myenv\Scripts\activate # On Windows
# Now pip will install to the virtual environment
pip install package-name
# Verify packages are installed
pip listVirtual environments:
- Create a fully isolated Python environment
- Work even when system Python is read-only
- Don't require any special permissions
- Are the Python community standard for project work
Verify whether the filesystem is actually read-only at the system level:
# Check mount options for the Python installation
df -h /usr/lib/python3
mount | grep python
# Try to determine what is read-only
mount | grep "\(ro\|read-only\)"
# Check if you can write to a test file in the directory
touch /usr/lib/python3/test.txtIf the filesystem is mounted read-only:
- You likely don't have system administrator access
- You should use --user or virtual environment workarounds
- Contact your system administrator if you need write access
If working in Docker, ensure the Python installation directory has proper permissions:
# Bad: mounting as read-only
FROM python:3.11
WORKDIR /app
# Then running: docker run -v /path/to/site-packages:/usr/local/lib/python3.11/site-packages:ro
# Good: use virtual environment or allow write access
FROM python:3.11
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /app
# Now pip installs to the virtual environment
RUN pip install package-nameBest practices for Docker:
- Use virtual environments in containers
- Don't mount site-packages directories as read-only
- If you need read-only filesystems, use --user with a WORKDIR you can write to
On some restricted systems, running pip as a module may work better:
# Instead of: pip install package-name
# Try: python -m pip install package-name
python -m pip install --user package-name
# Or with a virtual environment
source myenv/bin/activate
python -m pip install package-nameRunning pip as a module sometimes has different permission behavior than the pip command. This is particularly useful in:
- ChromeOS environments
- Certain containerized systems
- Systems where the pip executable has unusual permissions
- Python installations with special security policies
Install Python to a user-writable location using pyenv or conda:
# Using pyenv (installs to ~/.pyenv)
curl https://pyenv.run | bash
pyenv install 3.11.0
pyenv local 3.11.0
# Now pip will use your user-installed Python
pip install package-name
# Using conda/miniconda
conda create -n myenv python=3.11
conda activate myenv
conda install package-name # or: pip install package-nameBenefits:
- Complete control over Python installation
- No system administrator needed
- Multiple Python versions available
- Packages install to user-owned locations
- Reproducible across systems
If you need system-wide package installation and the filesystem is read-only:
# Request one of the following solutions from your administrator:
# 1. Remount the filesystem with write permissions
# 2. Create a writable site-packages directory
# 3. Install required packages system-wide themselves
# 4. Grant you sudo/administrative access if appropriateWhat to tell your administrator:
- Specify which packages you need installed
- Explain the [Errno 30] Read-only file system error you're encountering
- Ask if they can either:
- Remount /usr or the installation directory without the read-only flag
- Pre-install packages you need system-wide
- Grant temporary write access for installation
Meanwhile, use the --user or virtual environment workarounds.
Advanced notes
Read-only filesystems are often intentional security measures in production environments, cloud platforms, and shared systems. Some modern Linux distributions use overlay filesystems or container-like isolation where certain directories are mounted read-only by default. In ChromeOS, for example, the /usr filesystem is deliberately read-only to protect system integrity. Understanding when to work around read-only restrictions (--user, venv) versus when to request system changes (contact admin) is important for system security and stability. For CI/CD pipelines, always ensure your build environment has virtual environments properly configured before attempting pip installs. Never attempt to force write access to system directories that are read-only intentionally.
Frequently asked questions
- What does "EROFS" mean?
- The "OSError: [Errno 30] Read-only file system" error occurs when pip attempts to write package files to a directory that has been mounted or configured as read-only. This prevents pip from modifying, creating, or installing any files in that location. The error code EROFS (Error Read-Only FileSystem) indicates the underlying filesystem itself is mounted as read-only, which is a system-level restriction that pip cannot bypass.
- How do I fix "EROFS"?
- When installing Python packages, you may encounter an OSError [Errno 30] indicating the site-packages directory or Python installation path is read-only. This typically occurs in restricted environments like ChromeOS, containerized systems, or when the filesystem is mounted as read-only.
- What causes "EROFS"?
- The site-packages directory or Python installation path is mounted as read-only (most common) Running pip in a restricted environment like ChromeOS or containerized systems Filesystem is mounted read-only due to system configuration or system administrator policy
- Is the "EROFS" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Python Official Documentation
- ๐ฌStack Overflow - Read-only file system error(Stack Overflow)
- ๐ฌNixOS Discourse - Read-only filesystem with pip(Stack Overflow)
- ๐
- ๐Python venv documentation(Official Docs)
- ๐