Search code examples
pythonwindowspip

pip how to remove incorrectly installed package with a leading dash: "-pkgname"


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?


Solution

  • 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.