Check if a Debian package is installed from Python

后端 未结 7 1546
一生所求
一生所求 2020-12-31 03:20

Is there an elegant and more Python-like way to check if a package is installed on Debian?

In a bash script, I\'d do:

dpkg -s packagename | grep Stat         


        
7条回答
  •  盖世英雄少女心
    2020-12-31 03:41

    This is a pythonic way:

    import apt
    cache = apt.Cache()
    if cache['package-name'].is_installed:
        print "YES it's installed"
    else:
        print "NO it's NOT installed"
    

提交回复
热议问题