ModuleNotFoundError: No module named 'dnf' when running yum or dnf

polmonroig picture polmonroig · Dec 22, 2018 · Viewed 10.5k times · Source

A few days ago I wanted to run dnf but I received the following error

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

Thus I tried to run yum and I received something similar:

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

I do not know what happened and I hope someone can help me find the problem and solve it. The only thing I know is that it might be related to the fact that a few days before I installed tensorflow in python using conda. Although it seems conda does not work now because I get this:

Traceback (most recent call last):
  File "/usr/bin/conda", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
    @_call_aside
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 581, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 898, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 784, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'conda==4.5.11' distribution was not found and is required by the application

I am using fedora 29 Thanks!

Answer

mixify picture mixify · Mar 22, 2019

I had the same problem, but after all trial and error the only thing actually worked was:

rpm -qa python3

This will announce your python3 rpm package.

I've searched and downloaded it from web

Go to the downloaded directory like:

sudo rpm -e --nodeps python3-3.7.2-4.fc29.x86_64(my python3 rpm package)
sudo rpm -i python3-3.7.2-4.fc29.x86_64.rpm

I tried many other methods so this'll not be a only factor that resolve that problem.