code: def is_installed(pkg_name):
      
      with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True):
          res = run("dpkg -s %(pkg_name)s" % locals())
          for line in res.splitlines():
              if line.startswith("Status: "):
                  status = line[8:]
                  if "installed" in status.split(' '):
                      return True
          return False
docs: Check if a package is installed.