[root@localhost ~]# dnf --version
Traceback (most recent call last):
File "/usr/bin/dnf", line 57, in <module>
from dnf.cli import main
File "/usr/lib/python2.7/site-packages/dnf/init.py", line 30, in <module>
import dnf.base
File "/usr/lib/python2.7/site-packages/dnf/base.py", line 29, in <module>
import libdnf.transaction
File "/usr/lib64/python2.7/site-packages/libdnf/init.py", line 3, in <module>
from . import conf
File "/usr/lib64/python2.7/site-packages/libdnf/conf.py", line 17, in <module>
_conf = swig_import_helper()
File "/usr/lib64/python2.7/site-packages/libdnf/conf.py", line 16, in swig_import_helper
return importlib.import_module('_conf')
File "/usr/lib64/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named _conf
解决方法:
因为服务器环境为CentOS 7,没有完全预装在 CentOS 7 中,所以需要先全安装DNF。
yum install epel-release
yum install dnf
dnf --version
二、解决办法
1、先升级python:
#yum update python*
2、再安装以下软件:
bash
yum -y install dnf-data dnf-plugins-core libdnf-devel libdnf python2-dnf-plugin-migrate dnf-automatic
3、测试
[root@localhost ~]# dnf --version
4.0.9
Installed: dnf-0:4.0.9.2-2.el7_9.noarch at Tue 09 Apr 2024 06:06:01 PM CST
Built : CentOS BuildSystem <http://bugs.centos.org> at Wed 07 Apr 2021 03:52:38 PM CST
Installed: rpm-0:4.11.3-48.el7_9.x86_64 at Tue 09 Apr 2024 06:13:58 PM CST
Built : CentOS BuildSystem <http://bugs.centos.org> at Wed 24 Nov 2021 04:33:39 PM CST