65

After running pip freeze I noticed the following warning on top of the list:

WARNING: Could not parse requirement: -atplotlib

So I checked the installed packages using pip list, and indeed the following is considered a package:

Package         Version
--------------- -------
-atplotlib      3.0.3

I assume I probably had a typo when installing/upgrading matplotlib, which led to the aforementioned "package" being installed.

But I am not able to remove it as pip uninstall -atplotlib is read as a command and returns the following error:

No such option: -a

I found the following folders:

C:\Users\name\Anaconda3\Lib\site-packages\~atplotlib

C:\Users\name\Anaconda3\Lib\site-packages\~atplotlib-3.0.3-py3.7.egg-info

Is it safe, and sufficient, to remove them?

2
  • How did you find the relevant folders? i.e. C:\Users\name\Anaconda3\Lib\site-packages\~atplotlib. Is there some python code (from os or sys library) to find this directory? I am asking because I did not install anaconda. I installed Python through VS Code (which downloads python from the MS store)
    – Xtiaan
    Feb 15 at 11:05
  • Running pip list actually also mentions the directory.
    – Xtiaan
    Feb 15 at 11:08

4 Answers 4

58

It is safe to delete the offending folder(s) from your site-packages directory.

More info below (source):

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.

4
  • 9
    Link is golden.
    – Timo
    Jan 3, 2021 at 12:50
  • 1
    How can I delete all offending folder(s), where are they located?
    – alper
    Apr 25, 2021 at 11:42
  • 4
    On windows, check C:\Anaconda3\Lib\site-packages May 13, 2021 at 13:47
  • "perhaps pip crashed?" -- in my case, I was running a virtualenv in WSL, and VSCode in remote mode was locking a couple of my packages when I tried to update. This caused the artifacts to remain in my site-packages folder. Deleting the offending folders worked perfectly. Aug 11, 2021 at 1:29
33

EDIT: According to this link, provided by Lawrence in his answer

looking for and deleting the incorrectly named folders in your site-package directory should solve the issue.

If this is not sufficient, continue the cleaning as explained below.

Searching for the name of the broken package (without the leading dash) allowed me to find the following two folders:

C:\Users\name\Anaconda3\Lib\site-packages~atplotlib

C:\Users\name\Anaconda3\Lib\site-packages~atplotlib-3.0.3-py3.7.egg-info

Following Hoefling's comment (below)

I checked the SOURCES.txt file in the egg-info directory %dir%/~atplotlib-3.0.3-py3.7.egg-info/SOURCES.txt. Went through the list of paths in this file and made sure all paths listed did not contained ~. Then I renamed the directory ~atplotlib-3.0.3-py3.7.egg-info into atplotlib-3.0.3-py3.7.egg-info (removed the tilde ~).
Finally, I ran pip uninstall atplotlib, which prompted the following:

Uninstalling atplotlib-3.0.3:
Would remove:
C:\Users\name\Anaconda3\Lib\site-packages\atplotlib-3.0.3-py3.7.egg-info C:\Users\name\Anaconda3\Lib\site-packages\matplotlib
C:\Users\name\Anaconda3\Lib\site-packages\pylab.py

Proceeding with the removal solved the issue (the warning disappeared and the package is not anymore on the package list.

9
  • 2
    The problem is that you have not removed all the installed files by doing that and since you have removed the egg-info dir, you don't have the info about the installed files (file ~atplotlib-3.0.3-py3.7.egg-info/SOURCES.txt). You should go through the list of paths in this file and make sure all paths listed there don't contain ~ and match the paths on disk (renaming if necessary). Then rename the only directory ~atplotlib-3.0.3-py3.7.egg-info to remove the tilde (e.g. atplotlib-3.0.3-py3.7.egg-info), then pip uninstall atplotlib.
    – hoefling
    Jul 11, 2019 at 8:58
  • Looking at the matplotlib installation, you should have mpl_toolkits dir and pylab.py module remaining in the C:\Users\name\Anaconda3\Lib\site-packages dir (maybe also with tilde prepended). Removing those should complete the cleanup.
    – hoefling
    Jul 11, 2019 at 9:02
  • @hoefling Hi, thanks for the instructions. I can easily restore the two folders if that helps with the clean up process (I backed them up)
    – CAPSLOCK
    Jul 11, 2019 at 9:04
  • @removing the ~ from the folder and running pip uninstall atplotlib I get the following: Uninstalling atplotlib-3.0.3: Would remove: C:\Users\name\Anaconda3\Lib\site-packages\atplotlib-3.0.3-py3.7.egg-info, C:\Users\name\Anaconda3\Lib\site-packages\matplotlib, C:\Users\name\Anaconda3\Lib\site-packages\pylab.py should I proceed?
    – CAPSLOCK
    Jul 11, 2019 at 9:09
  • 1
    On my end I had to remove the folder instead of doing pip uninstall <pkg>
    – alper
    Apr 25, 2021 at 11:54
3

I received the following error myself, after executing: python -m pip install --upgrade pip --user

WARNING: Ignoring invalid distribution -ip (c:\python310\lib\site-packages)

  1. I went to the file specification within the C:\
  2. Located the -ip (it was located at the top) and I deleted it.
  3. Executed the code again

Results:

Requirement already satisfied: pip in c:\users\GhostFace\appdata\roaming\python\python310\site-packages (21.3.1)

0

I had to do rm -rf atplotlib after removing ~ character as beginning of the file name.

$ pip freeze | grep atplotlib
$ cd /home/user/.local/lib/python3.8/site-packages
$ mv \~ atplotlib atplotlib
$ pip freeze | grep atplotlib
atplotlib ==3.0.3
$  pip uninstall atplotlib
WARNING: Skipping atplotlib as it is not installed.
$ rm -rf atplotlib

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.