Uninstalling all Python dependencies

Originally posted on 2024-05-06

Python doesn’t want you to be able to install, uninstall, or even know the name of the packages you need. If you’ve ever gotten this dreaded error then you know what I mean.

ModuleNotFoundError: No module named 'google'

But if you want to get Python back and uninstall everything you’re able to install you can, like a monkey shaking a bag of parts hoping they’ll assemble, run this a bunch of times:

pip freeze | sort -R | awk '{print $1}' | xargs pip uninstall -y

This will list all of your packages, sort them randomly, get the name of the package (because Python loves putting weird stuff after the name to trip you up), and then uninstall as many as possible.

If you hit something that won’t uninstall you can run it again and as long as you’re not all the way down to the uninstallable packages you’ll eventually uninstall something else. Repeat this 5, 10, or more times, and you’ll see your global Python dependencies erode away like a jagged stone in a rock tumbler until you have a silky smooth system with minimal crap on it.