Reputation: 1017
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!
Upvotes: 9
Views: 47753
Reputation: 1157
I too had the same error message and tried some various things to no avail. I did get it working again after doing the following:
Then all worked! I'll be more careful before replacing entirely Python in the future. Do look into pyenv and/or virtualenv.
Upvotes: 0
Reputation: 1101
I had similar problem on Rocky Linux 9 Docker image (with pre-installed Python 3.9) when installing Python 3.11 from packages.
dnf install python3.11
python3.11
executable worked fine, but when setting a symlink python3.11 -> python3
$ ls -l /usr/bin/pyth*
lrwxrwxrwx 1 root root 16 Sep 19 12:53 /usr/bin/python -> /usr/bin/python3
lrwxrwxrwx 1 root root 19 Sep 19 12:53 /usr/bin/python3 -> /usr/bin/python3.11
-rwxr-xr-x 1 root root 15448 Jun 23 06:04 /usr/bin/python3.11
-rwxr-xr-x 1 root root 15440 Apr 17 23:46 /usr/bin/python3.9
dnf stopped working with ModuleNotFoundError: No module named 'dnf'
error because its Python modules are installed in /usr/lib/python3.9/site-packages/dnf
directory.
Solution: for me helped to replace default #!/usr/bin/python3
shebang in /usr/bin/dnf
Python script with a specific one #!/usr/bin/python3.9
:
sed -i 's|#!/usr/bin/python3|#!/usr/bin/python3.9|g' /usr/bin/dnf
Then with
$ head -1 /usr/bin/dnf
#!/usr/bin/python3.9
it works fine:
$ dnf --version
4.14.0
Upvotes: 10
Reputation: 111
I had the same problem on Linux master01 4.19.90-17.5.ky10.aarch64
,
It may be because the first line of configuration in /usr/bin/yum
is incorrect and needs to be modified to the correct python path.
vim /usr/bin/yum
#!/usr/bin/python -> #!/usr/bin/python2 or #!/usr/bin/python3
If the path is normal, then there may be a lack of dnf
related dependencies. This is very complicated, you can refer toHere's my fix
Upvotes: 2
Reputation: 827
had the same error.
my fix ->
cd into /usr/bin. has many python files...
latest python (3.11) has pytest, python3 -> python3.11 (symlink), python3.11, python3.11-config, python3.11-x86_64-config, python -> python3
had been using 3.9, not familiar with python so much, so changed symlink back to python3->python3.9 after Fedora 36 update changed symlink to 3.11 and installed python3.11. when i changed symlink back to 3.9, this created the error message. When i changed the symlink back to python3->python3.11 the error disappeared and all works fine. DNF is fine etc. did nothing else.
since all the other python files were pointing to the 3.11 versions, introduction of the symlink to 3.9 must have blown the fuse...
Upvotes: 1
Reputation: 1
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
Upvotes: 0
Reputation: 11
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
$ while read -r line;do dirname $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
$ while read -r line;do dirname $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.
Upvotes: 0
Reputation: 329
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.
Upvotes: 1
Reputation: 61
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.
Upvotes: 6