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.
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.
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.
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.
ValueError: math domain error
How to fix "ValueError: math domain error" in Python
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages'
How to fix "Permission denied" when installing packages with pip
socket.gaierror: [Errno -2] Name or service not known
How to fix "socket.gaierror: [Errno -2] Name or service not kn" in Python
pydantic_core._pydantic_core.ValidationError: 1 validation error
How to fix "pydantic_core._pydantic_core.ValidationError: 1 va" in Python
pydantic.errors.PydanticUserError: `@validator` is deprecated, use `@field_validator`
How to fix "pydantic.errors.PydanticUserError: `@validator` is" in Python