Is there any Python code to get the list of packages installed on Ubuntu along with the version of the package? I have seen Python code at Generating list of manually installed packages and querying individual packages. But that doesn't have the listing of version ID. Can anyone know how to get the version of the installed packages?
I'm not sure if there is existing code for that. But you can look at file
/var/lib/dpkg/status. All information about installed packages is stored in this file.
To write code that will parse this file is pretty easy even in case you're not great in python.
Not sure if this shouldn't be migrated to askubuntu, but just use the same approach as in the mentioned thread. Run dpkg/dpkg-query to get a dump of all the data and use standard python parsing mechanisms to extract the relevant information.
Of course, since you're already forking, you can do all the text mangling in bash itself.
Alternatively, find the state file that contains versions, if there is any ("Dir::Etc::Status"?). This approach would be the cleanest.
--format) option to aptitude to specify which fields are displayed.
aptitude --disable-columns -F '%p %v' search '~A'
From Python, use the
apt_pkg module from the