Back to top
Edit this page
Toggle table of contents sidebar
Usage#
Unix/macOS
python -m pip uninstall [options] <package> ... python -m pip uninstall [options] -r <requirements file> ...
Windows
py -m pip uninstall [options] <package> ... py -m pip uninstall [options] -r <requirements file> ...
Description#
Uninstall packages.
pip is able to uninstall most installed packages. Known exceptions are:
-
Pure distutils packages installed with
python setup.py install
, which
leave behind no metadata to determine what files were installed. -
Script wrappers installed by
python setup.py develop
.
Options#
- -r, —requirement <file>#
-
Uninstall all the packages listed in the given requirements file. This option can be used multiple times.
- -y, —yes#
-
Don’t ask for confirmation of uninstall deletions.
- —root-user-action <root_user_action>#
-
Action if pip is run as a root user. By default, a warning message is shown.
- —break-system-packages#
-
Allow pip to modify an EXTERNALLY-MANAGED Python installation
Examples#
-
Uninstall a package.
Unix/macOS
$ python -m pip uninstall simplejson Uninstalling simplejson: /home/me/env/lib/python3.9/site-packages/simplejson /home/me/env/lib/python3.9/site-packages/simplejson-2.2.1-py3.9.egg-info Proceed (Y/n)? y Successfully uninstalled simplejson
Windows
C:\> py -m pip uninstall simplejson Uninstalling simplejson: /home/me/env/lib/python3.9/site-packages/simplejson /home/me/env/lib/python3.9/site-packages/simplejson-2.2.1-py3.9.egg-info Proceed (Y/n)? y Successfully uninstalled simplejson
How do I uninstall all packages installed by pip from my currently activated virtual environment?
Mateen Ulhaq
24.7k19 gold badges102 silver badges136 bronze badges
asked Jun 28, 2012 at 15:36
blueberryfieldsblueberryfields
46.2k28 gold badges90 silver badges168 bronze badges
2
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
If you have packages installed directly from github/gitlab, those will have @
.
Like:
django @ git+https://github.com/django.git@<sha>
You can add cut -d "@" -f1
to get just the package name that is required to uninstall it.
pip freeze | cut -d "@" -f1 | xargs pip uninstall -y
answered Jun 28, 2012 at 18:32
blueberryfieldsblueberryfields
46.2k28 gold badges90 silver badges168 bronze badges
26
This will work for all Mac, Windows, and Linux systems.
To get the list of all pip packages in the requirements.txt file (Note: This will overwrite requirements.txt if exist else will create the new one, also if you don’t want to replace old requirements.txt then give different file name in the all following command in place requirements.txt).
pip freeze > requirements.txt
Now to remove one by one
pip uninstall -r requirements.txt
If we want to remove all at once then
pip uninstall -r requirements.txt -y
If you’re working on an existing project that has a requirements.txt
file and your environment has diverged, simply replace requirements.txt
from the above examples with toberemoved.txt
. Then, once you have gone through the steps above, you can use the requirements.txt
to update your now clean environment.
And For single command without creating any file as @joeb suggested
pip uninstall -y -r <(pip freeze)
Nam G VU
33.4k69 gold badges234 silver badges374 bronze badges
answered Nov 12, 2016 at 18:08
13
I wanted to elevate this answer out of a comment section because it’s one of the most elegant solutions in the thread. Full credit for this answer goes to @joeb.
pip uninstall -y -r <(pip freeze)
This worked great for me for the use case of clearing my user packages folder outside the context of a virtualenv which many of the above answers don’t handle.
Edit: Anyone know how to make this command work in a Makefile?
Bonus: A bash alias
I add this to my bash profile for convenience:
alias pipuninstallall="pip uninstall -y -r <(pip freeze)"
Then run:
pipuninstallall
Alternative for Pipenv
If you are using pipenv, you can run:
pipenv uninstall --all
Alternative for Poetry
If you are using Poetry, run:
poetry env remove --python3.9
(Note that you need to change the version number there to match whatever your Python version is.)
answered Mar 9, 2018 at 18:51
7
This works with the latest. I think it’s the shortest and most declarative way to do it.
virtualenv --clear MYENV
But why not just delete and recreate the virtualenv?
Immutability rules. Besides it’s hard to remember all those piping and grepping the other solutions use.
answered Jul 26, 2012 at 15:15
Robert MoskalRobert Moskal
21.8k8 gold badges62 silver badges86 bronze badges
4
I managed it by doing the following:
- Create the requirements file called
reqs.txt
with currently installed packages list
pip freeze > reqs.txt
- Then uninstall all the packages from
reqs.txt
# -y means remove the package without prompting for confirmation
pip uninstall -y -r reqs.txt
I like this method as you always have a pip requirements file to fall back on should you make a mistake. It’s also repeatable, and it’s cross-platform (Windows, Linux, MacOs).
answered Oct 29, 2019 at 11:32
0
Other answers that use pip list
or pip freeze
must include --local
else it will also uninstall packages that are found in the common namespaces.
So here are the snippet I regularly use
pip freeze --local | xargs pip uninstall -y
Ref: pip freeze --help
answered Aug 3, 2017 at 4:49
nehemnehem
12.9k6 gold badges59 silver badges85 bronze badges
1
Method 1 (with pip freeze
)
pip freeze | xargs pip uninstall -y
Method 2 (with pip list
)
pip list | awk '{print $1}' | xargs pip uninstall -y
Method 3 (with virtualenv
)
virtualenv --clear MYENV
answered Jun 5, 2016 at 13:25
SuriyaaSuriyaa
2,2222 gold badges25 silver badges44 bronze badges
2
On Windows if your path
is configured correctly, you can use:
pip freeze > unins && pip uninstall -y -r unins && del unins
It should be a similar case for Unix-like systems:
pip freeze > unins && pip uninstall -y -r unins && rm unins
Just a warning that this isn’t completely solid as you may run into issues such as ‘File not found’ but it may work in some cases nonetheless
EDIT: For clarity: unins
is an arbitrary file which has data written out to it when this command executes: pip freeze > unins
That file that it written in turn is then used to uninstall the aforementioned packages with implied consent/prior approval via pip uninstall -y -r unins
The file is finally deleted upon completion.
answered Dec 6, 2015 at 14:01
0
I use the —user option to uninstall all the packages installed in the user site.
pip3 freeze --user | xargs pip3 uninstall -y
Kermit
4,9594 gold badges42 silver badges75 bronze badges
answered Apr 1, 2020 at 7:56
DeanDean
5374 silver badges8 bronze badges
5
For Windows users, this is what I use on Windows PowerShell
pip uninstall -y (pip freeze)
answered Mar 23, 2018 at 12:57
benwrkbenwrk
3682 silver badges7 bronze badges
0
First, add all package to requirements.txt
pip freeze > requirements.txt
Then remove all
pip uninstall -y -r requirements.txt
answered Jan 8, 2019 at 10:03
shafikshafik
6,1085 gold badges32 silver badges51 bronze badges
0
Best way to remove all packages from the virtual environment.
Windows PowerShell:
pip freeze > unins ; pip uninstall -y -r unins ; del unins
Windows Command Prompt:
pip freeze > unins && pip uninstall -y -r unins && del unins
Linux:
pip3 freeze > unins ; pip3 uninstall -y -r unins ; rm unins
answered Sep 14, 2022 at 18:40
SathiamoorthySathiamoorthy
9,1119 gold badges65 silver badges77 bronze badges
3
The quickest way is to remake the virtualenv completely. I’m assuming you have a requirements.txt file that matches production, if not:
# On production:
pip freeze > reqs.txt
# On your machine:
rm $VIRTUALENV_DIRECTORY
mkdir $VIRTUALENV_DIRECTORY
pip install -r reqs.txt
answered Jun 28, 2012 at 15:37
Ned BatchelderNed Batchelder
365k75 gold badges564 silver badges662 bronze badges
1
GabLeRoux
16.8k16 gold badges63 silver badges81 bronze badges
answered Sep 10, 2016 at 4:50
zeskzesk
3072 silver badges6 bronze badges
1
Its an old question I know but I did stumble across it so for future reference you can now do this:
pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...
-r, —requirement file
Uninstall all the packages listed in the given requirements file. This option can be used multiple times.
from the pip documentation version 8.1
answered Mar 23, 2016 at 14:33
CraicerjackCraicerjack
6,2132 gold badges31 silver badges39 bronze badges
(adding this as an answer, because I do not have enough reputation to comment on @blueberryfields ‘s answer)
@blueberryfields ‘s answer works well, but fails if there is no package to uninstall (which can be a problem if this «uninstall all» is part of a script or makefile). This can be solved with xargs -r
when using GNU’s version of xargs
:
pip freeze --exclude-editable | xargs -r pip uninstall -y
from man xargs
:
-r, —no-run-if-empty
If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there
is no input. This option is a GNU extension.
answered Jul 5, 2019 at 11:24
pip3 freeze --local | xargs pip3 uninstall -y
The case might be that one has to run this command several times to get an empty pip3 freeze --local
.
answered Oct 17, 2019 at 18:26
obotezatobotezat
1,06116 silver badges20 bronze badges
1
pip uninstall `pip freeze --user`
The --user
option prevents system-installed packages from being included in the listing, thereby avoiding /usr/lib
and distutils
permission errors.
answered Jan 3 at 0:25
mcpmcp
1,9264 gold badges24 silver badges28 bronze badges
1
This was the easiest way for me to uninstall all python packages.
from pip import get_installed_distributions
from os import system
for i in get_installed_distributions():
system("pip3 uninstall {} -y -q".format(i.key))
Huey
5,1106 gold badges33 silver badges44 bronze badges
answered Jun 18, 2017 at 20:06
the easy robust way
cross-platform
and work in pipenv as well is:
pip freeze
pip uninstall -r requirement
by pipenv:
pipenv run pip freeze
pipenv run pip uninstall -r requirement
but won’t update piplock or pipfile so be aware
answered Oct 11, 2019 at 18:10
This works on my windows system
pip freeze > packages.txt && pip uninstall -y -r packages.txt && del packages.txt
The first part pip freeze > packages.txt
creates a text file with list of packages installed using pip along with the version number
The second part pip uninstall -y -r packages.txt
deletes all the packages installed without asking for a confirmation prompt.
The third part del packages.txt
deletes the just now created packages.txt.
answered Jun 23, 2021 at 11:15
SohailAQSohailAQ
1,0021 gold badge13 silver badges25 bronze badges
Cross-platform support by using only pip
:
#!/usr/bin/env python
from sys import stderr
from pip.commands.uninstall import UninstallCommand
from pip import get_installed_distributions
pip_uninstall = UninstallCommand()
options, args = pip_uninstall.parse_args([
package.project_name
for package in
get_installed_distributions()
if not package.location.endswith('dist-packages')
])
options.yes = True # Don't confirm before uninstall
# set `options.require_venv` to True for virtualenv restriction
try:
print pip_uninstall.run(options, args)
except OSError as e:
if e.errno != 13:
raise e
print >> stderr, "You lack permissions to uninstall this package.
Perhaps run with sudo? Exiting."
exit(13)
# Plenty of other exceptions can be thrown, e.g.: `InstallationError`
# handle them if you want to.
answered Feb 21, 2015 at 3:45
Samuel MarksSamuel Marks
1,6411 gold badge20 silver badges27 bronze badges
On Windows if your path is configured correctly, you can use:
pip freeze > unins && pip uninstall -y -r unins && del unins
answered Apr 19, 2021 at 18:53
Why not just rm -r .venv
and start over?
answered Aug 12, 2022 at 18:15
Evan ZamirEvan Zamir
8,09114 gold badges56 silver badges83 bronze badges
1
This is the command that works for me:
pip list | awk '{print $1}' | xargs pip uninstall -y
answered Jun 2, 2016 at 22:12
Fei XieFei Xie
1071 silver badge2 bronze badges
If you’re running virtualenv
:
virtualenv --clear </path/to/your/virtualenv>
for example, if your virtualenv is /Users/you/.virtualenvs/projectx
, then you’d run:
virtualenv --clear /Users/you/.virtualenvs/projectx
if you don’t know where your virtual env is located, you can run which python
from within an activated virtual env to get the path
answered Oct 27, 2016 at 21:57
punkrockpollypunkrockpolly
9,3206 gold badges36 silver badges37 bronze badges
In Command Shell of Windows, the command
pip freeze | xargs pip uninstall -y
won’t work. So for those of you using Windows, I’ve figured out an alternative way to do so.
- Copy all the names of the installed packages of pip from the
pip freeze
command to a .txt file. - Then, go the location of your .txt file and run the command
pip uninstall -r *textfile.txt*
answered Dec 26, 2017 at 6:39
If you are using pew
, you can use the wipeenv command:
pew wipeenv [env]
answered Jan 11, 2019 at 10:57
I simply wanted to remove packages installed by the project, and not other packages I’ve installed (things like neovim
, mypy
and pudb
which I use for local dev but are not included in the app requirements). So I did:
cat requirements.txt| sed 's/=.*//g' | xargs pip uninstall -y
which worked well for me.
answered Jan 20, 2021 at 23:39
verbozeverboze
4191 gold badge7 silver badges10 bronze badges
Select Libraries To Delete From This Folder:
C:\Users\User\AppData\Local\Programs\Python\Python310\Lib\site-packages
answered Dec 11, 2021 at 9:05
1
-
Home
-
News
- PIP Uninstall All Python Packages in Windows – See a Full Guide!
By Vera | Follow |
Last Updated
If you have installed a Python package, you want to uninstall it due to some reason. Then, how to uninstall Python package with PIP? After reading this detailed guide on PIP uninstall given by MiniTool, you know what you should do.
What Is PIP?
Before introducing something on how to uninstall PIP packages, let’s first see a general introduction to Python PIP.
PIP is a package manager in Python that is used to install and manage Python packages. This tool allows you to install and manage Python applications and their dependencies. Package management is very important, so PIP is pre-installed in most Python distributions. By default, Python 3.4 and later & Python 2.7.9 and later (on the Python2 series) include PIP.
If you install a Python package, due to some reason, you may want to uninstall it. Well then, how to uninstall Python package with PIP? Follow the guide here now to know some details.
Related article: How to Install PIP on Windows/Mac/Linux Easily
PIP Uninstall Package – How to Do in Windows
In this part, we show you some commands to uninstall PIP packages, and let’s see them one by one.
PIP Uninstall Packagename
Using this command, you can remove the installed package one by one. This method only works when you have already added Python to the Windows path. If you don’t know how to add it, you can go to press Win + R, type sysdm.cpl and click OK to open System Properties. Go to Advanced > Environment Variables. Under User variables, click New, and edit Variable name and Variable value.
In terms of Variable value, it should include the Python application path and Python Scripts path. To find them, right-click on your Python app (which can be found via the Windows search bar) and choose Open file location. Then, right-click on the Python shortcut and choose Open file location. The app path can be seen like C:\Users\cy\AppData\Local\Programs\Python\Python311. The Scripts path should be C:\Users\cy\AppData\Local\Programs\Python\Python311\Scripts.
Next, see how to uninstall PIP.
Step 1: In Windows, open Command Prompt with admin rights.
Step 2: Type cd\ into the CMD window and press Enter.
Step 3: Type cd followed by the Python Scripts path and here is an example – cd C:\Users\cy\AppData\Local\Programs\Python\Python311\Scripts. Then, press Enter.
Step 4: Execute this command – pip uninstall package_name. Replace the package name with the one you have installed like pandas. See an example pip uninstall pandas.
Step 5: Type y to confirm the uninstallation when asked. Now, your Python package is removed from your computer.
PIP Uninstall All Packages
If you want to delete all the packages installed by PIP, you can use the pip freeze command. It can help you list all the installed packages via PIP and uninstall them without asking for confirmation. The correct type of this command is pip uninstall -y -r <(pip freeze).
If you want, you can save the installed packages in a file called requirements.txt and directly uninstall PIP packages from the file. Run these commands:
pip freeze > requirements.txt
pip uninstall -r requirements.txt This helps to uninstall packages one by one.
pip uninstall -r requirements.txt -y This helps to delete all the packages at once.
In addition to pip freeze, you can also use xargs to uninstall all the PIP packages. The command is pip freeze | xargs pip uninstall -y. If you have packages installed via VCS (like GitLab, Github, Bitbucket, etc.), you need to exclude them and then uninstall Python packages with PIP via this command – pip freeze | grep -v “^-e” | xargs pip uninstall -y.
Final Words
How to uninstall Python package with PIP or how to uninstall PIP packages? After reading this guide on PIP uninstall, try the given ways to easily remove packages from your Windows computer if you need. If you have any ideas, let us know in the comment part.
About The Author
Position: Columnist
Vera is an editor of the MiniTool Team since 2016 who has more than 7 years’ writing experiences in the field of technical articles. Her articles mainly focus on disk & partition management, PC data recovery, video conversion, as well as PC backup & restore, helping users to solve some errors and issues when using their computers. In her spare times, she likes shopping, playing games and reading some articles.
Речь про пакеты установленные через pip глобально. В моем случае под WIndows 10, но этот способ также будет работать и под Linux и должно работать под макосью.
PHP
1 2 |
pip freeze > 1.txt pip uninstall —y —r 1.txt |
Здесь pip freeze выводит список всех установленных пакетов. pip install удаляет заданный пакет, а с аргументом -r удаляет по списку. Аргумент -y избавляет от необходимости соглашаться ручками в консоли при удалении каждого из пакетов в списке.
Pip uninstall all is used for removing packages and dependencies
by Henderson Jayden Harper
Passionate about technology, Crypto, software, Windows, and everything computer-related, he spends most of his time developing new skills and learning more about the tech world. He also enjoys… read more
Updated on
- Pip uninstall helps you remove unnecessary packages from Python.
- Removing the pip packages from the Python environment will aid in unclustering them
XINSTALL BY CLICKING THE DOWNLOAD
FILE
Over time, as you work on various Python projects, your environment may become cluttered with multiple packages. So, using pip to uninstall all packages can help resolve it.
Therefore, we will explore ways to remove all packages installed by pip to have a clean Python environment. Also, we have a detailed guide about how to install pip on macOS in simple steps.
What is pip?
Pip is a package management system for installing and managing software packages written in Python. It stands for Pip Installs Packages or Pip Installs Python. Pip is the standard package installer for Python and is widely used in the Python community.
Here are some of the main functions of pip:
- Pip lets you easily install Python packages from the Python Package Index (PyPI) or other sources.
- It automatically resolves and installs the dependencies required by a package.
- Pip enables you to manage installed packages, including upgrading, downgrading, or uninstalling them.
- You can search PyPI to discover available Python packages and their versions.
- It helps you manage package versions, allowing you to specify the desired version or range of versions for installation.
- Pip provides tools for packaging and distributing Python packages, making it easier to share your own code with others.
- It integrates well with virtual environments, allowing you to isolate and manage dependencies for different projects.
- Pip can be used to upgrade its own version to the latest release.
What does pip uninstall do?
As its name says, pip uninstall is in charge of uninstalling Python packages. However, it can’t remove the following:
- Pure distutils packages that leave no metadata
- Script wrappers
How can I pip uninstall all packages in Windows?
1. Uninstall the individual package
- Press the Windows button, type Command Prompt, and select Run as Administrator to open it.
- Type the following and press Enter to know the list of packages installed:
pip list
- Then, type this and press Enter:
pip uninstall package_name
Using the command above will uninstall the particular package name entered. Note: substitute the package name with the individual package you want to remove.
You can read our guide about how to fix Command Prompt not working on your PC.
2. Remove all packages
- Press the Windows button, type Command Prompt, and select Run as Administrator to open it.
- Type the following and press Enter:
pip uninstall -y -r <(pip freeze)
- Reply with the following and press Enter to confirm your selection:
Y
Adding the pip freeze command will remove all packages installed on your system by pip.
- Are Windows 11 ADMX Templates Backward Compatible?
- Fix: Monitor is Stuck at 60Hz on Windows 11
3. Remove all packages using use xargs
- Press the Windows button, type Command Prompt, and select Run as Administrator to open it.
- Type the following in the command prompt and press Enter:
pip freeze | xargs pip uninstall -y
- THen, input this code and press Enter to exclude the VCS package:
pip freeze | grep -v "^-e" | xargs pip uninstall -y
- Type the following and press Enter:
pip freeze --user | xargs pip uninstall -y
You can only individually remove packages installed from VCS (version control systems). Thus, you will have to exclude them before the command can run.
In conclusion, check our detailed guide about resolving PIP not recognized in PyCharm terminus on Windows OS. Also, we have a complete guide on Visual Studio vs PyCharm to help you decide which IDE is best for your next project.
Should you have further questions or suggestions regarding this guide, kindly drop them in the comments section.