检查是否从 Python 安装了 Debian 软件包
问题描述
是否有一种优雅且更像 Python 的方法来检查软件包是否安装在 Debian 上?
Is there an elegant and more Python-like way to check if a package is installed on Debian?
在 bash 脚本中,我会这样做:
In a bash script, I'd do:
dpkg -s packagename | grep Status
建议在 Python 脚本中做同样的事情?
Suggestions to do the same in a Python script?
解决方案
这是pythonic的方式:
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"
相关文章