Determine if package installed with Yum Python API?
import yum
yb = yum.YumBase()
if yb.rpmdb.searchNevra(name='make'):
print "installed"
else:
print "not installed"
Pythonic way to check if a package is installed or not
import sys
import rpm
ts = rpm.TransactionSet()
mi = ts.dbMatch( 'name', sys.argv[1] )
try :
h = mi.next()
print "%s-%s-%s" % (h['name'], h['version'], h['release'])
except StopIteration:
print "Package not found"
- TransactionSet() will open the RPM database
- dbMatch with no paramters will set up a match iterator to go over the entire set of installed packages, you can call next on the match iterator to get the next entry, a header object that represents one package
dbMatch can also be used to query specific packages, you need to pass the name of a tag, as well as the value for that tag that you are looking for:
dbMatch('name','mysql')
Check if one package is installed in my system with Python?
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.
How do I check if an rpm package is installed using Python?
import os
rpm = 'binutils'
f = os.popen('rpm -qa')
arq = f.readlines()
if rpm in arq:
print("{} is installed".format(rpm))
Determining the path that a yum package installed to
yum uses RPM, so the following command will list the contents of the installed package:
$ rpm -ql package-name
to what location on disk does yum installs python packages by default?
I got it by little bit of digging ,
I searched like this :
rpm -ql python2-rpdb-0.1.5-2el7.1.noarch
its installed in the /usr/lib/python2.7/site-packages folder
or in /usr/lib64/python2.7/
How to find out name of package I want to remove with Yum in Amazon Fedora EC2 instance
Your question is not very clear, but I'll try to answer.
1. You installed python3.7 your self
when you installed python3.7, you typed
yum install python3
so if you want to remove it, you can type the same name that you use to install it:
yum remove python3
2. someone else installed it
In this case you can trace the binary that you want to remove, let's say python3.7
. First you can see what is the full path of that binary:
which python3.7
which gives
/usr/bin/python3.7
now you can query which package installed that file:
rpm -qf /usr/bin/python3.7
which will yield the full package name, something like:
python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64
which you can then use to remove it:
yum remove python36-3.6.8-2.module_el8.0.0+33+0a10c0e1.x86_64
Related Topics
How to Solve Unicodedecodeerror in Python 3.6
Python Multiprocessing - Debugging Oserror: [Errno 12] Cannot Allocate Memory
Python & Ms Word: Convert .Doc to .Docx
How to Get Apache to Serve Static Files on Flask Webapp
Using Pyinotify to Watch for File Creation, But Waiting for It to Be Completely Written to Disk
Python Requests, How to Specify Port for Outgoing Traffic
Install Scipy with Mkl Through Pip
Python Error - "Importerror: Cannot Import Name 'Dist'"
Letsencrypt Importerror: No Module Named Interface on Amazon Linux While Renewing
Why am I Getting Socket.Gaierror: [Errno -2] from Python Httplib
Python Logging - Check Location of Log Files
Will Python Systemrandom/Os.Urandom Always Have Enough Entropy for Good Crypto
How to Start/Stop Linux Processes with Python
Python Detect Linux Shutdown and Run a Command Before Shutting Down
Convert Timestamps With Offset to Datetime Obj Using Strptime