I think you using either AIX 7.1 or AIX 7.2 system here. The dnf (& dnf modules) in these AIX levels are 32-bit based as rpm itself(from rpm.rte) is 32-bit. The default python3 ie., /opt/freeware/bin/python3 is 64bit. So to import dnf modules you have to use 32bit python3 which is /opt/freeware/libexec/python3.9_32.
# oslevel -s
7200-05-09-2446
# head /opt/freeware/bin/dnf
#!/opt/freeware/libexec/python3.9_32
# The dnf executable script.
#
# Copyright (C) 2012-2016 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
But what is your use case here ? why you want to manually do "import dnf" inside python interpreter ?
Original Message:
Sent: Wed October 29, 2025 11:13 PM
From: Justin Kaipada
Subject: Ansible: Could not import the dnf python module using /usr/bin/python3.9
I saw this same error, however i was already using python3.9 from the freeware directory, I have however hit this error on my VM
$ /opt/freeware/bin/python3.9
Python 3.9.24 (main, Oct 21 2025, 04:27:28)
[GCC 10.3.0] on aix
Type "help", "copyright", "credits" or "license" for more information.
>>> import dnf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/freeware/lib/python3.9/site-packages/dnf/__init__.py", line 30, in <module>
import dnf.base
File "/opt/freeware/lib/python3.9/site-packages/dnf/base.py", line 29, in <module>
import libdnf.transaction
File "/opt/freeware/lib/python3.9/site-packages/libdnf/__init__.py", line 3, in <module>
from . import common_types
File "/opt/freeware/lib/python3.9/site-packages/libdnf/common_types.py", line 13, in <module>
from . import _common_types
ImportError: 0509-022 Cannot load module /opt/freeware/lib/python3.9/site-packages/libdnf/_common_types.so.
0509-026 System error: Cannot run a file that does not have a valid format.
>>>
------------------------------
Justin Kaipada
Original Message:
Sent: Wed July 16, 2025 07:11 AM
From: Ayappan P
Subject: Ansible: Could not import the dnf python module using /usr/bin/python3.9
https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html#using-python-3-on-the-managed-machines-with-commands-and-playbooks
------------------------------
Ayappan P
Original Message:
Sent: Wed July 16, 2025 07:04 AM
From: Paul Clayton
Subject: Ansible: Could not import the dnf python module using /usr/bin/python3.9
Hi,
How would one point it to use that version of python
------------------------------
Paul Clayton
Original Message:
Sent: Wed July 16, 2025 06:55 AM
From: Ayappan P
Subject: Ansible: Could not import the dnf python module using /usr/bin/python3.9
You won't be able to use dnf python module using /usr/bin/python3.9 (AIX base provided python3.9). You can do it using "/opt/freeware/bin/python3.9"
------------------------------
Ayappan P
Original Message:
Sent: Wed July 16, 2025 06:44 AM
From: Paul Clayton
Subject: Ansible: Could not import the dnf python module using /usr/bin/python3.9
Hi,
When deploying packages via Ansible, I get the following error. This happens on AIX 7.2 & 7.3
fatal: [myhost]: FAILED! => {"changed": false, "msg": "Could not import the dnf python module using /usr/bin/python3.9 (3.9.19 (main, Jul 30 2024, 07:16:53) [IBM XL C/C++ for AIX 16.1.0.14]). Please install `python3-dnf` or `python2-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python2', '/usr/bin/python'])", "results": []}
------------------------------
Paul Clayton
------------------------------
#AIXOpenSource