How do I remove all python packages?
Warning!
This is an answer to your question!
pip
has an option that allows you to process an uninstall without confirmation: --yes
. So if you get all packages and then execute them one by one with the uninstaller, you'll remove all of them.
To do that you can use the xargs
command: it will allow you to use \n
as a separator (see man xargs for more information)
so all that together is just one command that will remove all of the installed Python packages::
pip freeze | xargs pip uninstall --yes
Related videos on Youtube
matejom
Updated on September 18, 2022Comments
-
matejom over 1 year
I am relatively new to this. I have installed various python2.7 packages, sometimes with apt-get, sometimes with pip, sometimes from source. I am experiencing millions of different issues when trying to remove, upgrade or install a new package. So, I want to remove ALL python packages, and start with a clean installation. Is there a relatively safe way to do this?
-
matejom over 7 yearsSo reinstall ubuntu then? Or is there a way to identify the packages which will not crash my system
-
Sergiy Kolodyazhnyy over 7 yearsLook into /var/log/apt , there's bunch of history logs. Read through them using less and zless commands and find what packages you installed. But if you don't mind reinstalling then do that - simplest way
-
Jacob Vlijm over 7 years@Serg then there is pip, I never use that, not sure what it does and where. > reinstalling seems best.
-
Sergiy Kolodyazhnyy over 7 years@jacobvlijm pip is like apt but only for Python. I am not sure if it will remove what was installed via apt though.
-
Phillip -Zyan K Lee- Stockmann over 7 years@Serg pip won't remove apt-stuff but works in
/usr/local/lib/python*/
instead - per default at least. If one would force it to/usr/lib/
anything might happen :-D -
Ron over 7 yearsRemove all packages inside
/usr/local/lib/python[your-version-here]
. You can eitherrm -r
contents of that directory or usepip uninstall <package name>
-
matejom over 7 years@Ron you probably mean /usr/local/lib/python[your-version-here]/dist-packages. The problem is that pip does not see packages installed from source or with apt, and since this has been going on for more than a year, i really do not know which one was installed with what method. I have fixed the problem for now, managed to re install the libraries that I need for now, I will backup my scripts, and wait for the impending armageddon before I re-install ubuntu. Jacob, Serg, Phillip and Ron, thanks
-
Fabby about 6 years@SergiyKolodyazhnyy See below answer...
-
Sergiy Kolodyazhnyy about 6 yearsNow that I have read this question 3 times very very slowly, what pops out is " I am experiencing millions of different issues when trying to remove, upgrade or install a new package", which is clearly an XY problem and absolutely no clarity on what millions of issues appear and what method they use to deal with packages.
-
-
Sergiy Kolodyazhnyy about 6 yearsOK, but should be noted this is a very unforgiving approach. I've installed
pip3
from scratch andpip3 freeze
showed list packages even before I installed anything at all, which tells me this may remove more than one actually needs, i.e. not just stuff OP themselves installed viapip install <package>
. -
Fabby about 6 yearsIt's what he asked for, no? Remove all Python packages?
-
Sergiy Kolodyazhnyy about 6 yearsOP doesn't always know what they ask and what sort of implications it may have. Not saying it's a wrong interpretation, just giving a word of caution.
-
Fabby about 6 years@SergiyKolodyazhnyy Warning added! :-)