pythonpython-3.xansiblepython-3.6dnf

dnf installs python3 modules only for platform-python


I'm currently working on an Ansible project which relies on python. For the ansbile package module the python3-dnf module is required. On the destination Server (AlmaLinux 8.6) python3-dnf is already installed:

$ dnf install python3-dnf
Last metadata expiration check: 3:36:12 ago on Thu 06 Oct 2022 07:42:20 AM CEST.
Package python3-dnf-4.7.0-8.el8.alma.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

I found out, that python3-dnf is only installed for the platform-python version 3.6:

$ ls -l /usr/lib/python3.6/site-packages/
[...]
drwxr-xr-x.  9 root root 4.0K Oct  6 11:08 dnf
drwxr-xr-x.  3 root root 4.0K May 10 19:36 dnf-plugins
drwxr-xr-x.  3 root root   44 Sep  5 10:29 dnfpluginscore

$ /usr/libexec/platform-python
Python 3.6.8 (default, Sep 13 2022, 07:19:15)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dnf
>>>

Because when I try to import dnf with my latest installed python version 3.9:

Python 3.9.7 (default, Apr 21 2022, 08:39:11)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dnf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dnf'

So here is my question: Is it possible to tell dnf ( dnf install python3-dnf ) to insall python modules not for the platform-python version but for the latest python version intalled or specify a python version?

Thanks


Solution

  • I found out, that python3-dnf is only installed for the platform-python version 3.6:

    dnf can only install Python modules for the version of Python distributed with AlmaLinux. If you dnf install python3, you'll have a /usr/bin/python3 binary that can see Python modules installed using dnf.

    If you're installing Python 3.9 via some other mechanism, you'll need to manually manage your dependencies.

    I'm currently working on an Ansible project which relies on python.

    Since you're using Ansible, one option is to simply use the platform-python version by setting ansible_python_interpreter=/usr/libexec/platform-python.