Not really sure why I wanted to know the installed packages of each Python version. But it turns out a bit of fun while coding.

At first, I went to site-packges to find the files:

find . -maxdepth 1 ! -name \*.egg-info ! -name \*.pth\* ! -name \*.py[co] ! -name _\* -printf %p\\n

It is incomplete and inaccurate. You can just run pydoc modules or help('modules') in interactive mode to get a list of modules or packages, so I wrote a script on top of that.

list() function grepd module names and lspm() is a recursive function. I have to use recursion because join only support two files at a time and I want this script to be able to list any number of Python, that is no hard-coded for join. Therefore, by using recursion with Process Substitution does the trick.

Here is a sample output:

$ ./lspm.sh
/usr/bin/python2.5...
/usr/bin/python2.6...
/usr/bin/python2.7...
/usr/bin/python3.2...
ArgImagePlugin          -  -    2.7  -
BaseHTTPServer          -  2.6  2.7  -
Bastion                 -  2.6  2.7  -
BdfFontFile             -  -    2.7  -
BmpImagePlugin          -  -    2.7  -
BufrStubImagePlugin     -  -    2.7  -
CDROM                   -  -    2.7  3.2
CGIHTTPServer           -  2.6  2.7  -
CXX                     -  -    2.7  3.2
ConfigParser            -  2.6  2.7  -
ContainerIO             -  -    2.7  -
Cookie                  -  2.6  2.7  -
[snip]
xdg                     -  -    2.7  -
xdrlib                  -  2.6  2.7  3.2
xml                     -  2.6  2.7  3.2
xmllib                  -  2.6  2.7  -
xmlrpc                  -  -    -    3.2
xmlrpclib               -  2.6  2.7  -
xxlimited               -  -    -    3.2
xxsubtype               -  2.6  2.7  3.2
yaml                    -  -    2.7  3.2
zipfile                 -  2.6  2.7  3.2
zipimport               -  2.6  2.7  3.2
zlib                    -  2.6  2.7  3.2

On my system, python-2.5 /usr/bin/pydoc modules throws an ImportError because of Portage module, which uses except ... as ...: syntax. So, when a module cause a problem for pydoc, then there will be no modules returned.