如何检查是否使用Python安装了rpm软件包? [英] How do I check if an rpm package is installed using Python?
本文介绍了如何检查是否使用Python安装了rpm软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个Python 2.7应用程序,该应用程序依赖于要安装的几个rpm软件包.计划在不久的将来移植到Python 3.是否有一个简单的函数调用来检查是否安装了在两个版本的Python中均可使用的rpm?
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?
例如
rpm = "binutils"
if package_installed(rpm):
print("{} is installed".format(rpm))
推荐答案
import os
rpm = 'binutils'
f = os.popen('rpm -qa')
arq = f.readlines()
if rpm in arq:
print("{} is installed".format(rpm))
这篇关于如何检查是否使用Python安装了rpm软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文