On 2018-07-20 08:04:33 +0200, Cecil Westerhof wrote: > I can get the installed version of a package with: > pip2 show cryptography | awk '/^Version: / { print $2 }' > > But I was wondering if there is a better way.
Using pip probably is the most reliable way (for packages installed via pip). Most packages have version information embedded, and most of them use the attribute __version__: >>> import chardet >>> chardet.__version__ '2.3.0' >>> import colorama >>> colorama.__version__ '0.3.2' >>> import psycopg2 >>> psycopg2.__version__ '2.5.4 (dt dec pq3 ext)' >>> import numpy >>> numpy.__version__ '1.8.2' But there are exceptions: >>> import xlrd >>> xlrd.__VERSION__ '0.9.2' or even: >>> import django >>> django.get_version() '1.7.11' So you can't rely on that. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | h...@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list