问题
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