Python scripts running on Rocky Linux 8 can not “import yum”

by ,

We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

Operating System and Software

  • Rocky Linux 8
  • Python 2.7
  • Python 3.6


  • python2/python3 scripts fail to import the python module
  • When I run my python script that is copied over from CentOS 7 or before, the following is seen:
Traceback (most recent call last):
ImportError: No module named yum

How to Fix

Migrate any scripts making use of the Legacy YUM v3 API to the newer YUM v4 API.

Origin of the Problem

Disclaimer: We are not responsible for the content of external links.

With the migration to Rocky Linux 8, the Legacy YUM v3 APIs are no longer available. This is documented in the following:

Rocky Linux – 8 – Considerations in adopting Rocky Linux 8 – Chapter 6. Software management – Red Hat Customer Portal

Rocky Linux – 8 – 8.0 release notes – Chapter 4. New features – Red Hat Customer Portal

From the above, the following is applicable:

Note that the legacy Python API provided by YUM v3 is no longer available. Users are advised to migrate their plug-ins and scripts to the new API provided by YUM v4 (DNF Python API), which is stable and fully supported. The DNF Python API is available at DNF API Reference.

Diagnostic Steps

1) Verify the version of Rocky Linux 8

$ cat /etc/redhat-release 
Rocky Linux release 8.0 (Ootpa)

2) Verify that the module is not loadable:

$ python3 -c "import yum"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'yum'

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.