How to uninstall all packages installed by pip
Codemia Knowledge Hub ·
To uninstall every pip-installed package, run pip freeze | xargs pip uninstall -y. It lists every installed package and passes the list to pip uninstall with automatic confirmation. Depending on the situation, deleting the virtual environment or using pip-autoremove can be the better choice.
pip freeze piped to pip uninstall
pip freezeoutputs every installed package inpackage==versionformatxargspasses each line as an argument topip uninstall-yauto-confirms every uninstall prompt
On Windows (PowerShell)
PowerShell has no xargs by default. Use:
Or go through a requirements file:
With a requirements file (any OS)
-r makes pip read package names from a file, just like pip install -r requirements.txt.
Deleting the virtual environment instead
Inside a virtual environment, the simplest reset is to delete it and create a fresh one:
This guarantees no leftover files, cached data or partially installed packages. It is the better choice when you want a completely clean slate, suspect corrupted installs, are resetting a development environment, or have accumulated experimental packages over time.
Removing one package and its orphaned dependencies
To remove a package plus the dependencies nothing else needs, use pip-autoremove:
It is the pip equivalent of apt autoremove on Debian/Ubuntu.
Keeping pip, setuptools and wheel
To remove almost everything but keep the package tooling:
On Windows PowerShell:
Using pipx for command-line tools
Tools like black, flake8 or httpie installed with pip are better managed by pipx, which gives each tool its own isolated environment:
This keeps tools from polluting project environments in the first place.
Comparing the methods
| Method | Scope | Removes dependencies | Cross-platform | Leaves pip intact |
pip freeze | xargs pip uninstall -y | All packages | N/A (removes everything) | Linux/Mac | Yes |
| Requirements file approach | All packages | N/A (removes everything) | Yes | Yes |
| Delete virtual environment | All packages + env | Yes (everything gone) | Yes | N/A (env deleted) |
pip-autoremove | One package + orphans | Yes | Yes | Yes |
Filtered pip freeze | All except specified | N/A | Linux/Mac | Yes (if excluded) |
Why a second pass is sometimes needed
Some packages have circular dependencies or install hooks that reinstall dependencies during uninstallation, so the first pass may miss some. Run it again and verify:
Anything still listed after two passes is usually installed at the system level or ships with the Python distribution itself (like pip, setuptools and wheel).
Do not mass-uninstall from system Python
On Linux, system Python often has packages installed by the OS package manager (apt, yum, dnf). Removing them with pip can break system tools.
Check which Python you are on:
If which python points to /usr/bin/python or /usr/local/bin/python, you are likely on system Python. Create a virtual environment before installing packages:
Mistakes to avoid
- Leaving off
-y. pip then asks for confirmation on every package, which with 100+ packages means pressingyand Enter 100+ times. - Skipping verification. Circular dependencies can block some removals on the first pass, so run
pip freezeagain afterward. - Assuming
pip freezeshows everything. Packages installed with--editable(development mode) or from direct file paths may not appear. Usepip listfor a complete view. - Deleting the wrong virtual environment. Double-check the path before
rm -rf; there is no undo. - No backup. Export your current state with
pip freeze > backup_requirements.txtfirst so you can restore it.
Related reading
- How do I remove duplicates from a list, while preserving order?
- How do I remove leading whitespace in Python?
- How do I remove NaN values from a NumPy array?
- How do I remove packages installed with Python's easy_install?
- How do I remove files saying old mode 100755 new mode 100644 from unstaged changes in Git?
- How do I remove/delete a folder that is not empty?
- How do I remove the first item from a list?
- How do I remove whitespace from the end of a string in Python?
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.