检查是否从 Python 安装了 Debian 软件包 [英] Check if a Debian package is installed from Python

查看:30
本文介绍了检查是否从 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"

这篇关于检查是否从 Python 安装了 Debian 软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆