Cleaning up Python – and old libraries

Newer Ubuntu releases do not even pre install Python2, and after an upgrade and installing latest Python3.x included in the release, you likely have some old ones there too. Since you most likely will not be using the python2 unless you use some very old library, you can clean them up, clear a lot of disk space and use the “python3” / “pip3” command instead.

As seen above (in Disk Usage Analyzer), there are a lot of python2.7 libraries that will probably not ever be used in the near future – for example, try

pip uninstall wx

You may get an error like:

The directory ‘~/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Cannot uninstall requirement wx, not installed

it may be something installed in synaptic – some of these you can uninstall, some may be used by something you use. Click the “S” here after searching and those installed (green) will show at the top:

Right click and select remove, you may get a notice like this if you don’t want to remove those…

Sometimes when you “sudo pip uninstall sympy” or “sudo pip uninstall mercurial” or similar, you will gen an error:

Not uninstalling mercurial at /usr/lib/python2.7/dist-packages, outside environment /usr

Not uninstalling sympy at /usr/lib/python2.7/dist-packages, outside environment /usr

This seems to come up whenever you try to uninstall one that is installed with Ubuntu/Debian package manager. In this case, I uninstalled “mercurial” and “python-sympy” with Synaptic.

One important thing to note is that “pip install” should generally be “pip3 install” as python3 should be the one used since the discontinuing of python2.x last year. So try to be in the habit of using “python3” if you haven’t yet.

Bleachbit is also good to run from time to time as it will clean up various unused files and cache.

Unused versions of Python

“python –version” and “python3 –version” will tell you what versions of Python would be used on your system, so local home directory library folders are also likely not going to be in used. you can trash those and make sure those unused versions 3.4, 3.5, 3.6 from previous versions are not clogging up free space. Empty trash when you are sure they’re not used.

Leave a Reply

Your email address will not be published. Required fields are marked *

ninety ÷ ten =