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?

  • 1
    At the moment you succeed to uninstall all python packages, your system is unusable. You won't be able to do any basic action, including installing/uninstalling. Oct 11 '16 at 10:13
  • So reinstall ubuntu then? Or is there a way to identify the packages which will not crash my system
    – matejom
    Oct 11 '16 at 10:16
  • Look 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 Oct 11 '16 at 10:19
  • @Serg then there is pip, I never use that, not sure what it does and where. > reinstalling seems best. Oct 11 '16 at 10:25
  • 2
    Now 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. Feb 19 '18 at 20:09


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


  • 1
    OK, but should be noted this is a very unforgiving approach. I've installed pip3 from scratch and pip3 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 via pip install <package>. Feb 19 '18 at 20:09
  • It's what he asked for, no? Remove all Python packages?
    – Fabby
    Feb 19 '18 at 20:16
  • 2
    OP 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. Feb 19 '18 at 20:30
  • @SergiyKolodyazhnyy Warning added! :-)
    – Fabby
    Feb 19 '18 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.