Pip list has packages whose name starts with a hypen

When I run the command pip list on my computer (windows 10), at the very top of the list are some packages whose name starts with a hyphen. For example:
-ip
-atplotlib

In my site-packages directory, I can find folders with the same names, but a tilde instead of a hyphen.

Furthermore, they appear to have the same files in them as packages that sound similar (in the above examples, pip and matplotlib, respectively).

What are these packages and should I delete them off of my computer?

Welcome and thanks for posting here Gabe!

That’s definitely a bug. Could you file an issue on pip’s issue tracker, with clear steps for reproducing this issue?

Feel free to delete those folders from your system, they aren’t used by Python so they’re essentially no-ops.

1 Like

To add a bit more colour:

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.

I dug into this when it first came up. From what I could figure, the problem is that pkg_resources looks for .dist-info directories in sys.path. Any dist-info directory is identified as an installed distribution (thus listed by pip list), with the directory name parsed as distribution name (thus the dash-prefixed display).

I must admit there are (quite many) parts of pkg_resources I couldn’t fully figure out. Maybe this is another sign we should work on State of importlib.metadata - #7 by barry :smiley:

@steve.dower

I do have memory of using CTRL-C to force quit pip, and I know windows uses ~ to designate temp lock files. Probably what happened Thanks everyone.