Warning: Adam Matan discourages this use in pip > 10.0. Also, read @sinoroc's comment below
This was inspired by Adam Matan's answer (the accepted one):
import tabulatetry: from pip import get_installed_distributionsexcept: from pip._internal.utils.misc import get_installed_distributionstabpackages = []for _, package in sorted([('%s %s' % (i.location, i.key), i) for i in get_installed_distributions()]): tabpackages.append([package.location, package.key, package.version])print(tabulate.tabulate(tabpackages))
which then prints out a table in the form of
cd ~/pythonpython installed_packages.py
Output:
------------------------------------------- -------------- ------/home/pi/.local/lib/python2.7/site-packages enum-compat 0.0.2/home/pi/.local/lib/python2.7/site-packages enum34 1.1.6/home/pi/.local/lib/python2.7/site-packages pexpect 4.2.1/home/pi/.local/lib/python2.7/site-packages ptyprocess 0.5.2/home/pi/.local/lib/python2.7/site-packages pygatt 3.2.0/home/pi/.local/lib/python2.7/site-packages pyserial 3.4/usr/local/lib/python2.7/dist-packages bluepy 1.1.1/usr/local/lib/python2.7/dist-packages click 6.7/usr/local/lib/python2.7/dist-packages click-datetime 0.2/usr/local/lib/python2.7/dist-packages construct 2.8.21/usr/local/lib/python2.7/dist-packages pyaudio 0.2.11/usr/local/lib/python2.7/dist-packages tabulate 0.8.2------------------------------------------- -------------- ------
which lets you then easily discern which packages you installed with and without sudo
.
A note aside: I've noticed that when I install a packet once via sudo
and once without, one takes precedence so that the other one isn't being listed (only one location is shown). I believe that only the one in the local directory is then listed. This could be improved.