pip "WARNING: Ignoring invalid distribution" in CI
pip found a directory in site-packages whose name starts with ~ (a tilde), which is the artifact of an interrupted or partial uninstall. pip cannot read it as a valid distribution and warns on every command.
What this error means
Nearly every pip command prints "WARNING: Ignoring invalid distribution -X (/path/site-packages)". Installs may still work, but the warning signals a corrupted package directory.
WARNING: Ignoring invalid distribution -umpy (/usr/lib/python3.12/site-packages)
WARNING: Ignoring invalid distribution -ip (/usr/lib/python3.12/site-packages)Common causes
An interrupted install or uninstall
A cancelled or OOM-killed pip operation left a ~ame rename directory that pip later cannot parse.
A cached/persisted environment carried the corruption forward
Reusing a cached site-packages directory across runs preserves the stray ~ directories.
How to fix it
Remove the stray tilde directories
- Identify the site-packages path from the warning.
- Delete the directories whose names begin with a tilde.
- Re-run pip; the warning should be gone.
python -c "import site,glob,os; [print(p) for p in glob.glob(os.path.join(site.getsitepackages()[0], '~*'))]"
# then remove them
find "$(python -c 'import site;print(site.getsitepackages()[0])')" -maxdepth 1 -name '~*' -exec rm -rf {} +Use a clean virtual environment
Create a fresh venv per run so no corrupted state persists.
python -m venv .venv && . .venv/bin/activate
pip install -r requirements.txtHow to prevent it
- Use a fresh virtual environment per CI run.
- Avoid caching the full site-packages directory; cache the wheel/download dir instead.
- Do not interrupt pip mid-install in scripts.