Question: Removing Incorrectly Installed Package with a Leading Dash (-pkgname) via Pip
This issue arises when an incorrectly installed package appears with a leading dash (-) in its name, such as "-atplotlib" in this instance. Removing it via pip uninstall -atplotlib fails, resulting in an error.
Answer:
-
Safety of Manual Removal: It is safe to manually remove the offending folder(s) from the site-packages directory, as pip now renames them during uninstallation and only deletes them upon successful completion. If deletion fails, the directories are renamed back.
-
Directory Locations: The mentioned directories containing "-atplotlib" (Libsite-packages~atplotlib and ~atplotlib-3.0.3-py3.7.egg-info) can be safely removed.
Further Explanation:
As per the source, pip has improved its uninstallation process:
-
Previous Method: Pip would copy the entire package contents to another directory, potentially on a different drive, then copy them back if needed, resulting in slower performance.
-
New Method: Pip renames the offending directories to prevent imports, ensuring that everything will succeed before deleting them. This improves performance, especially for packages with numerous files.
In this specific case, it seems that the deletion step failed, causing the directories to persist.
The above is the detailed content of How to safely remove a package installed with a leading dash (-) using pip?. For more information, please follow other related articles on the PHP Chinese website!