What is the easiest way to remove all packages installed by pip?
I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv:
pip freeze | xargs pip uninstall -y
In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):
pip freeze | grep -v "^-e" | xargs pip uninstall -y
How do I remove all packages installed by PIP?
The following command should do the trick:
pip freeze > requirements.txt && pip uninstall -r requirements.txt -y
Alternatively you can skip the creation of any intermediate files (i.e. requirements.txt
):
pip uninstall -y -r <(pip freeze)
How to uninstall a package installed with pip install --user
Having tested this using Python 3.5 and pip 7.1.2 on Linux, the situation appears to be this:
pip install --user somepackage
installs to$HOME/.local
, and uninstalling it does work usingpip uninstall somepackage
.This is true whether or not
somepackage
is also installed system-wide at the same time.If the package is installed at both places, only the local one will be uninstalled. To uninstall the package system-wide using
pip
, first uninstall it locally, then run the same uninstall command again, withroot
privileges.In addition to the predefined user install directory,
pip install --target somedir somepackage
will install the package intosomedir
. There is no way to uninstall a package from such a place usingpip
. (But there is a somewhat old unmerged pull request on Github that implementspip uninstall --target
.)Since the only places
pip
will ever uninstall from are system-wide and predefined user-local, you need to runpip uninstall
as the respective user to uninstall from a given user's local install directory.
Remove all pip packages
I could remove everything like this:
To get room permissions:
sudo su
and then removed anything on this location:
/usr/local/lib/python3.9/site-packages/
Simplest way to uninstall all PIP packages outside of venv on Windows
You can run this in command prompt(no adminstrator priveleges) prompt:
pip freeze > packagelist.txt
pip uninstall -r .\packagelist.txt -y
Another more programmatic way would be :
$packages = pip freeze
foreach ($package in $packages ){
pip uninstall $package -y
}
both work the same but the first example creates a .txt file, you may want to delete that
Related Topics
Break // in X Axis of Matplotlib
How to Update/Upgrade Pip Itself from Inside My Virtual Environment
Find_Element_By_* Commands Are Deprecated in Selenium
Most Efficient Way of Making an If-Elif-Elif-Else Statement When the Else Is Done the Most
Merging Several Python Dictionaries
Making a Request to a Restful API Using Python
How to Display Custom Values on a Bar Plot
Imread Returns None, Violating Assertion !_Src.Empty() in Function 'Cvtcolor' Error
How to Filter Rows Containing a String Pattern from a Pandas Dataframe
Decode Escaped Characters in Url
Making Python Loggers Output All Messages to Stdout in Addition to Log File
Implementing Slicing in _Getitem_
Df.Append() Is Not Appending to the Dataframe
How to Check a String for Specific Characters
How to Intercept Calls to Python's "Magic" Methods in New Style Classes