I have played around a lot with my Python installations (2 and 3) and installed a bunch of packages, some using apt-get
, but most using pip
. I have also upgraded many apt
-installed packages with pip
to a newer version.
My question is:
How can I reverse all those changes, remove all pip
-installed Python packages and just keep the default set of preinstalled packages in their default repository version, plus those installed by apt-get
but only as dependency of other software, always downgrading to the repository version if necessary.
I want to do this to have a tidied up Python environment for the system and have my modifications in virtualenvs only.
Is that possible without a system reinstall? How would I approach it?
I would start by listing the Python packages managed by
apt-get
(the following one-liner takes a few seconds to run, be patient):Note: if necessary, replace 2.7 with whatever python version you're interested in.
Next, uninstall the packages you installed manually. If you are unsure which ones you installed, you can get the list of all packages installed manually using the following command (see this question):
Then uninstall the Python packages you installed manually, for example:
Next, you want to know which packages you installed using pip:
This command lists the contents of pip's install directory sorted by last modification date, making it easier to find the packages you installed yourself. For example, I installed Google's
gcloud
tool which installs a bunch of pip packages that I don't want to uninstall, but looking through the list it's easy to see that they were all installed at the same exact time, so I know which ones I should leave, and which ones I can uninstall. Before you uninstall any pip package, you should take a snapshot of the list of packages installed:Then just uninstall the packages you want, for example:
Finally, don't forget that some pip packages may have been installed in your user directory. Perhaps you're fine with that, but if not, you can list them:
If you want to get rid of all these packages you can just delete this directory. Otherwise, just uninstall the individual packages, for example:
Don't forget to check for other python versions (e.g., 3.5).