ERROR pip system_error ai_generated true

ERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/root/.cache/pip/http'

ID: pip/cache-read-only-filesystem

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 23.0 active
pip 24.0 active
pip 24.2 active

Root Cause

pip's cache directory is located on a read-only filesystem (e.g., in a container, CI environment, or mounted volume with read-only permissions), preventing pip from writing or updating cached files.

generic

中文

pip 的缓存目录位于只读文件系统上(例如在容器、CI 环境或具有只读权限的挂载卷中),阻止 pip 写入或更新缓存文件。

Official Documentation

https://pip.pypa.io/en/stable/topics/caching/

Workarounds

  1. 95% success Disable pip's cache entirely: pip install --no-cache-dir <package>
    Disable pip's cache entirely: pip install --no-cache-dir <package>
  2. 90% success Set PIP_CACHE_DIR environment variable to a writable location: export PIP_CACHE_DIR=/tmp/pip-cache && pip install <package>
    Set PIP_CACHE_DIR environment variable to a writable location: export PIP_CACHE_DIR=/tmp/pip-cache && pip install <package>

中文步骤

  1. 完全禁用 pip 的缓存:pip install --no-cache-dir <package>
  2. 将 PIP_CACHE_DIR 环境变量设置为可写位置:export PIP_CACHE_DIR=/tmp/pip-cache && pip install <package>

Dead Ends

Common approaches that don't work:

  1. Run pip with sudo or as root to override permissions 90% fail

    The filesystem is genuinely read-only (e.g., mounted with -o ro); root cannot write to a read-only filesystem either. This often happens in Docker containers where the volume is mounted read-only.

  2. Delete the cache directory manually with rm -rf /root/.cache/pip 95% fail

    Deletion also requires write permission to the filesystem; the same read-only restriction applies.