Site icon GetPageSpeed

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

Operating System and Software

  • Rocky Linux 8
  • Python 2.7
  • Python 3.6

Problem

  • 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):
<snip>
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'
Exit mobile version