DNF not working after attempted Python upgrade

Hi! I tried to upgrade Python 3.7 to 3.8, but now when I try to run DNF I get this:
Traceback (most recent call last):
File “/usr/bin/dnf”, line 57, in
from dnf.cli import main
ModuleNotFoundError: No module named ‘dnf’

I installed 3.8, then did this:
sudo alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

and now I get that error. I tried undoing it like this but it didn’t work:
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1

Help?

Are you on F31? “Regular” or Silverblue?

How exactly did you do that?

I installed it with DNF, then ran the commands I put in the original post
(sudo dnf install python3.8)

You have declared both alternatives to python and python3 with the same priority. That’s inviting disaster.

Use
sudo alternatives --config python
and
sudo alternatives --config python3
to switch back to 3.7.

I knew it would be something stupid like that, thanks!

By the way, DO NOT change the system python. Use virtual envs or call the version of the interpreter you want to use.

https://developer.fedoraproject.org/tech/languages/python/multiple-pythons.html

You might need to clean up afterwards, with alternatives --remove.

2 Likes