Search code examples
pythonpython-3.xclangpython-importllvm-clang

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.')

Solution

  • 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.