How to reset OS:X installation of Python packages installed using sudo?

10,051

Nothing in my base installation of OS:X is installed with pip. This means you can uninstall everything from pip on your OSX without "worrying" - in terms of actual system performance. It is possible this will interfere with your day-to-day activities, if you are relying on global pip packages.

You can verify what packages you have installed by viewing the full list:

pip freeze

Everything this returns are user installations. This means you can "safely" pass this as arguments to pip uninstall:

pip freeze | xargs sudo pip uninstall -y

which will uninstall all items installed with pip on your machine.

You may accidentally be using these in some of your virtual environments, particularly if your PYTHONPATH variable is set to any of your local install directories. Any of pip's installed packages that are executables will also be visible inside of a virtual environment, assuming that you are not overwriting your PATH variable as part of your virtual environment.

In my case, the only item I had to reinstall was the virutalenv wrapper:

pip install virtualenvwrapper
Share:
10,051
enderland
Author by

enderland

Farewell Stack Exchange. o7 to everyone I've shared labors with over these many years. Take care.

Updated on July 26, 2022

Comments

  • enderland
    enderland almost 2 years

    Imagine that one did not realize how virtual environments work in Python and installed a lot of packages using sudo pip install for OS:X. Now they are facing problems managing package versions.

    This would never happen if one understands virtual environments, but if one did this prior to being enlightened, how can that someone easily remove all my their non-virtual environment packages that were installed, without breaking any default installations?

    Note this includes several programs (such as nosetests) and is not limited to exclusively libraries. It seems I can create a virtualenvironment with --no-site-packages and that gets around at least the packages (assuming I wipe my PYTHONPATH). But my actual PATH seems to let me see the executables I installed, too.

  • armand
    armand over 7 years
    This did not work for me. But for future viewers, this might: #!/bin/bash for i in $( pip freeze ); do sudo pip uninstall -y $i done. Found it here and here