How do I check if an rpm package is installed using Python? [duplicate]

徘徊边缘 提交于 2020-01-06 04:54:09

问题


I am writing a Python 2.7 app that relies on several rpm packages to be installed. There is a planned port to Python 3 in the near future. Is there a simple function call to check if an rpm is installed that works in both versions of Python?

e.g.

rpm = "binutils"
if package_installed(rpm):
    print("{} is installed".format(rpm))

回答1:


import os

rpm = 'binutils'

f = os.popen('rpm -qa')
arq = f.readlines()
if rpm in arq:
    print("{} is installed".format(rpm))


来源:https://stackoverflow.com/questions/59375889/how-do-i-check-if-an-rpm-package-is-installed-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!