Skip to content Skip to sidebar Skip to footer

Modulenotfounderror: No Module Named 'dnf' When Running Yum Or Dnf

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 from dnf.cli import

Solution 1:

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.

Solution 2:

Hello,

i have just been through this in Fedora 31 and do not exactly know what was the cause that led to this same issue, it must have been some package managing over another context that came up only on my next need to use DNF.

I am assuming that before this stated error:

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

You were having this message when executing dnf:

/usr/local/lib/python3.7/site-packages/dnf.py:15: UserWarning: The DNF Python API is not currently available via PyPI.

Please install it with your distro package manager (typically called
'python2-dnf' or 'python3-dnf'), and ensure that any virtual environments
needing the API are configured to be able to see the system site packages
directory.

After some hours researching and trying to install each DNF rpm dependency of the DNF rpm itself(https://pkgs.org/download/dnf) i felt as an intuition that maybe i should try to remove(mv sure)

/usr/local/lib/python3.7/

which had just one folder in it named site-packages

It worked!

Thank you.

Solution 3:

I have a friend who met the same problem.

He tried to uninstall python3.7 in linux server by some amazing cmd rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps and whereis python3 |xargs rm -frv. This caused the yum and dnf to break.

I changed the /usr/bin/yum to use a local python3.8 version, but it caused ModuleNotFoundError: No module named 'dnf' at last, and didn't solved it.

It is not a good way to download many rpm packages on the Internet. And I can't use yum either. But I have another same linux OS server, so I've tried to copy the correlation files about python3.7.

$ rpm -ql python3-3.7.0-9.h4.eulerosv2r8.aarch64> py.log
$ whileread -r line;dodirname$line |xargs -I {} ssh root@$remoteip"mkdir -p {}" ;scp $line root@$remoteip:$line  ;done<py.log

$ rpm -ql python3-libs-3.7.0-9.h4.eulerosv2r8.aarch64 >pylib.log
$ whileread -r line;dodirname$line |xargs -I {} ssh root@$remoteip"mkdir -p {}" ;scp $line root@$remoteip:$line  ;done<pylib.log

scp -r /usr/lib/python3.7/site-packages root@$remoteip:/usr/lib/python3.7/

I recovered yum this way.

Solution 4:

I had the same issue. For me the solution was to simply uninstall the python3 dnf package (including from all virtualenvs) that I had obviously installed somewhen.

pip uninstall dnf

Post a Comment for "Modulenotfounderror: No Module Named 'dnf' When Running Yum Or Dnf"