What This Error Means
pip detected that its cache directory is owned by a different user (often because pip was previously run with sudo), so it disables caching for safety.
How to Fix It
- Preferred: stop using
sudo pip ...and use a venv instead. - Fix the ownership/permissions of the pip cache directory to match your user (exact command varies by OS and policy).
- As a temporary workaround, bypass caching:
python -m pip install --no-cache-dir ....
Why It Happens
- pip was run with
sudoand created root-owned cache directories in your home path. - A shared home directory was modified by another user account.
- Permissions were changed by a system hardening step or file restore.
How to Verify
- Re-run pip and confirm the cache warning no longer appears.
- Run
python -m pip install <package>and confirm installs proceed normally.
Manual cache permission checks
- Find the cache directory:
python -m pip cache dir. - Check ownership:
ls -la ~/.cache/pip(and parent directories). - Check whether you previously used
sudo pip ...in this environment.
Common CLI Output
The directory '/home/user/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Why pip disables an unsafe cache
- pip uses a cache directory to speed up installs and reduce network downloads.
- If that directory is owned by another user, using it can be unsafe (permission errors, or writing files as the wrong user).
- pip disables the cache and prints instructions to fix ownership or
sudo -Hbehavior.
Prevention Tips
- Use venvs so you never need
sudofor pip installs. - In CI, set an explicit cache directory (
PIP_CACHE_DIR) owned by the job user. - Avoid sharing one cache directory across multiple Unix users.
Where This Can Be Triggered
github.com/pypa/pip/blob/25.3/src/pip/_internal/cli/base_command.py
pip disables caching if the configured cache directory is not owned (or not writable) by the current user, it also suggests sudo -H when relevant. - GitHub
if options.cache_dir:
options.cache_dir = normalize_path(options.cache_dir)
if not check_path_owner(options.cache_dir):
logger.warning(
"The directory '%s' or its parent directory is not owned "
"or is not writable by the current user. The cache "
"has been disabled. Check the permissions and owner of "
"that directory. If executing pip with sudo, you should "
"use sudo's -H flag.",
options.cache_dir,
)
options.cache_dir = None