2

I was trying to remove python environment and I think I accidentally removed the one comes default with fedora and makes dnf command not available.

I did(not consecutively but I think those three commands are the relevant ones):

sudo rm /bin/python
sudo rm /usr/bin/python
sudo rm /bin/python3 /bin/python3.12 /bin/python-argcomplete-check-easy-install-script /bin/python-argcomplete-tcsh

Then I found that:

n349@fedora:~/Downloads$ sudo dnf upgrade
Place your right index finger on the fingerprint reader
^C[sudo] password for n349: 
sudo: dnf: command not found

I tried to reinstall dnf, but it seems that dnf-4.19.0-1 is currently still installed on my machine and i cannot do it again.

~/Downloads$ dnf --version
bash: dnf: command not found...
Install package 'dnf' to provide command 'dnf'? [N/y] y


 * Waiting in queue... 
 * Loading list of packages.... Failed to install packages: dnf-4.19.0-1.fc39.noarch is already installed
n349@fedora:~/Downloads$ ls -l /usr/bin/dnf
lrwxrwxrwx. 1 root root 19 Mar 11 01:37 /usr/bin/dnf -> /usr/bin/dnf-4.19.0

I am using fedora 39 upgraded using dnf from fedora 38 preinstalled on a thinkpad x1 carbon.

n349@fedora:~/Downloads$ uname -a
Linux fedora 6.7.7-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Mar  1 16:53:59 UTC 2024 x86_64 GNU/Linux

I searched online and didn't found a solution to this problem and hope someone could help me to restore the functionality of dnf.

I tried to reinstall the dependencies:

$ sudo rpm -ivh --force dnf-data-4.19.0-1.fc39.noarch.rpm \
                      dnf-automatic-4.19.0-1.fc39.noarch.rpm \
                      python3-dnf-4.19.0-1.fc39.noarch.rpm \
                      yum-4.19.0-1.fc39.noarch.rpm

sudo rpm -ivh --force dnf-4.19.0-1.fc39.noarch.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:dnf-data-4.19.0-1.fc39           ################################# [ 25%]
   2:python3-dnf-4.19.0-1.fc39        ################################# [ 50%]
   3:dnf-automatic-4.19.0-1.fc39      ################################# [ 75%]
   4:yum-4.19.0-1.fc39                ################################# [100%]
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:dnf-4.19.0-1.fc39                ################################# [100%]

But it still does not work and the error messages change:

n349@fedora:~/Downloads$ dnf --version
bash: /usr/bin/dnf: cannot execute: required file not found

0

2 Answers 2

8

You need to reinstall the Python interpreter itself:

sudo rpm -Uvh https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-3.12.2-2.fc39.x86_64.rpm \
              https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-libs-3.12.2-2.fc39.x86_64.rpm

For future reference, everything under /usr (apart from /usr/local) belongs to the package manager; you mustn’t delete or change files there yourself. If you want to remove Python 3, run

sudo dnf remove python3

This will tell you why you shouldn’t try this, and give you the options to add in order to proceed.

1
  • Thanks for the tip, I will try not to break it again.
    – 943n
    Commented Mar 11 at 8:27
0
$ sudo rpm --reinstall --verbose --hash https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Retrieving https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:python3-3.12.2-2.fc39 ################################# [ 50%]
Cleaning up / removing...
2:python3-3.12.2-2.fc39 ################################# [100%]

$ rpm --query python3
python3-3.12.2-2.fc39.x86_64

$ dnf --version
4.19.0
Installed: dnf-0:4.19.0-1.fc39.noarch at Mon 11 Mar 2024 07:38:12 AM GMT
Built : Fedora Project at Tue 20 Feb 2024 02:19:51 PM GMT
Installed: rpm-0:4.19.1.1-1.fc39.x86_64 at Wed 21 Feb 2024 07:00:46 PM GMT
Built : Fedora Project at Wed 07 Feb 2024 04:05:57 PM GMT

References

2
  • 2
    You’d already reinstalled python3-dnf, the first command wasn’t necessary. Your second command from Reddit is a subset of the command in my answer. python3-dnf will always fail, it’s not a command. Commented Mar 11 at 8:42
  • I examined it in an uncorrect way. Thank you anyway.
    – 943n
    Commented Mar 11 at 9:07

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .