是否有一种优雅且更像 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"
这篇关于检查是否从 Python 安装了 Debian 软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!