使用Python检查系统中是否安装了一个软件包? [英] Check if one package is installed in my system with Python?

查看:1274
本文介绍了使用Python检查系统中是否安装了一个软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查系统中是否安装了某些软件包.我的系统是Linux,但如果可以在其他OS上使用,则更好.我的意思是特定于操作系统的软件包(例如* .rpm或* .deb).

How can I check is some package is installed in my system. My system is Linux, but even better if it could works in other OSs. I mean OS specific package (like could be *.rpm or *.deb).

是否有任何可以执行此操作的python模块或脚本?

Is there any python module or script that could do it?

推荐答案

要了解是否已安装.deb,.rpm等软件包,您需要为包装系统使用适当的工具.

To find out whether you've installed a .deb, .rpm, etc. package, you need to use the appropriate tools for your packaging system.

APT在Debian中有一个名为python-apt的Python包装器,或者只是 apt .

APT has a Python wrapper named python-apt in Debian, or just apt at PyPI.

RPM有大量的Python工具-实际上,Redhat的大多数安装程序生态系统都是基于Python构建的,因此您应该已经安装了rpm模块.阅读使用Python编程RPM (或者最好是搜索较新的版本……),这样您就可以了解自己的实际工作;即使是低级界面,也只有几行代码.

RPM has a whole slew of Python tools—in fact, most of Redhat's installer ecosystem is built on Python, and you should already have the rpm module installed. Read Programming RPM with Python (or, better, search for a newer version…) before looking for a high-level wrapper, so you understand what you're actually doing; it's only a couple lines of code even with the low-level interface.

据我所知,没有人将它们包装在通用工具中,可以存储任何Linux发行版曾经使用过的每种包装格式和数据库(即使使用过,也不会在linux系统上带来很多好处)不使用包装系统的产品).但是,如果您只想处理一些流行的系统,可以使用python-apt和Redhat自己的工具,或者在PyPI中搜索RPM,这将涵盖您所关心的几乎所有内容.

As far as I know, nobody has wrapped these up in a universal tool for every packaging format and database that any linux distro has ever used (and, even if they had, that wouldn't do you much good on linux systems that don't use a packaging system). But if you just want to handle a handful of popular systems, python-apt and either Redhat's own tools or search PyPI for RPM, and that will cover almost everything you care about.

或者, pkg-config 是最接近通用概念的东西此系统上安装的软件包".每个linux系统都会有它(以及大多数其他非Windows系统),但是不是每个软件包都向pkg-config注册.不过,如果您要查找的是 pkgconfig , Python答案.

Alternatively, pkg-config is the closest thing to a universal notion of "packages installed on this system". Every linux system will have it (and most other non-Windows systems), but not every package registers with pkg-config. Still, if this is what you're looking for, pkgconfig is the Python answer.

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

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