Nitanshu
Nitanshu

Reputation: 846

How to find the version of installed library in Python?

How can I find the version of clang installed on my system.

Link to clang lib: (click!)

I want functionality like:

if libclang.version < 3.4:  
    print('Clang version not supported.')

or some other logic so that I can find the version of clang.

There is no __version__ attribute in clang module. So I cannot do

if libclang.__version__ < 3.4
    print('Clang version not supported.')

Upvotes: 2

Views: 5043

Answers (3)

bfree67
bfree67

Reputation: 735

The simplest way to get all installed libraries is >>pip list

Upvotes: 3

Nitanshu
Nitanshu

Reputation: 846

from pkg_resources import get_distribution

if get_distribution('libclang-py3').version != '3.4.0':
    logging.error('clang version not supported')

get_distribution('pkg_name').version will return the version of the installed package, but this might not work in all cases.

Upvotes: 3

Talat Parwez
Talat Parwez

Reputation: 129

If you're unable to get the version of any packages directly, you can execute

pip freeze | grep clang

in your script and in order to get execute this script, you can use subprocess module of python as mentioned below:

>>> import subprocess
>>> p = subprocess.Popen(["pip", "freeze", "|", "grep", "clang"], stdout=subprocess.PIPE)
>>> p.communicate()[0].splitlines()
this will return all packages installed along with their packages and there you can have clang version.

Upvotes: 1

Related Questions