Python 3.11 overwrites dnf

I configure python3.11 with

./configure --enable-optimizations --prefix=/usr/bin

I compile & install it. I try to install libsdl2, but dnf does not work. It shows python instead.

Traceback (most recent call last):
  File "/usr/bin/dnf", line 61, in <module>
    from dnf.cli import main
ModuleNotFoundError: No module named 'dnf'

How can I fix it or reinstall dnf?

You cannot replace the default python on a Rocky Linux system without damaging it.

Your best bet is to download the default python RPM from dl.rockylinux.org and try to use rpm to reinstall it. Otherwise, you will need to reinstall your system.

1 Like

Thanks. Your method works. I am so glad that I do not have to reinstall the system again.

[root@localhost Downloads]# rpm -ivh python3-3.9.14-1.el9_1.1.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
        package python3-3.9.14-1.el9_1.1.x86_64 is already installed
[root@harrynotfound Downloads]# rpm --reinstall -vh python3-3.9.14-1.el9_1.1.x86_64.rpm 
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:python3-3.9.14-1.el9_1.1         ################################# [ 50%]
Cleaning up / removing...
   2:python3-3.9.14-1.el9_1.1         ################################# [100%]
[root@localhost Downloads]# dnf --version
4.12.0
  Installed: dnf-0:4.12.0-4.el9.noarch at Tue 20 Dec 2022 06:50:28 AM GMT
  Built    : Rocky Linux Build System (Peridot) <releng@rockylinux.org> at Tue 15 Nov 2022 09:28:34 AM GMT

  Installed: rpm-0:4.16.1.3-19.el9_1.x86_64 at Mon 28 Nov 2022 10:35:35 AM GMT
  Built    : Rocky Linux Build System (Peridot) <releng@rockylinux.org> at Tue 15 Nov 2022 04:42:25 PM GMT