2

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?

2

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.

1

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.

0

Pass the -F (--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 python-apt package.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.