900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 如何检测python是否安装_使用Python检查系统中是否安装了一个软件包?

如何检测python是否安装_使用Python检查系统中是否安装了一个软件包?

时间:2022-10-01 00:47:07

相关推荐

如何检测python是否安装_使用Python检查系统中是否安装了一个软件包?

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).

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

解决方案

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

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

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.

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.

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.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。