I did the fatal mistake of using "sudo pip" inside a virtual environment multiple times, and now all my virtual environments are a mess, failing in random ways when I try to install pip packages. I'm using Ubuntu 16.04. Is there anyway to reset the python/python3/pip/pip3 installations without reinstalling the entire system?
52 Answers
In theory you can remove the corresponding local Python directories in /usr/local/lib/ for the Python versions you want to reset (3.5 and 2.7 for a 16.04 Xenial system).
Namely the directories you'd purge would be /usr/local/lib/python3.5/dist-packages and /usr/local/lib/python2.7/dist-packages, then log out and log back in.
In testing, this erased the 'local' non-system-maintained (that is, not maintained by apt/dpkg) library sets. Removing those directories did not destroy
However, as I know nothing about your systems and were using basic test environments, containers, and VMs to isolate from my primary system, I can't guarantee this will totally fix your system, there may be other underlying issues that are not described or touched upon here that may be in play.
Also, if you do this, there is a chance a large number of things relying on the 'newer' versions will break, not enough to really mess with your system but enough to cause maybe your local projects to barf until you install the modules in userspace or in the dedicated virtual environments for each project.
2I needed to clean up disk space from Python packages safely. While this is a complete clean out of packages, I needed to move Python versions as well so I did not need old packages. I used the following to get all my package names, skip the first 2 lines and grab the first column, and uninstall without user interaction:
pip list | awk 'NR>2 {print $1}' | xargs -I {} pip uninstall -y {}Since your issue involved the use of sudo, I would modify some of these commands to make use of the global environment as sudo if needed such as the following:
pip list | awk 'NR>2 {print $1}' | xargs -I {} sudo pip uninstall -y {}