When I use pip to install or upgrade packages , I get below warnings.

WARNING: Ignoring invalid distribution -numpy (/home/j/tutorial-env/lib/python3.8/site-packages)

How can I fix it?


Go to your site-packages directory , to see if there is folder whose name start with ‘~’ tilde , if yes delete that folder

See? after deleting that folder no more “WARNING: Ignoring invalid distribution” anymore.

Wait, but why


When uninstalling a package, pip will now rename it in place to a name that cannot be imported, and once it has confirmed that everything will succeed (including installing new versions if it’s doing an upgrade), only then will it delete those folders. If something fails, it renames them back.

Previously, it would copy the entire contents to another directory, and potentially another drive, and then copy them back if it needed. So this change is a significant performance improvement, especially for packages with a lot of files in them.

What you’re seeing here is that the deletion failed for some reason - perhaps pip crashed? - and so the directories were not removed. I thought pip ignored them completely, but perhaps something else changed since I tested that?

The directories are safe to delete.