DNF新一代的RPM软件包管理器。克服了YUM包管理器的一些瓶颈,提升了包括用户体验,内存占用,依赖分析,运行速度等多方面的内容。
因为服务器环境为CentOS 7,它没有预装在 CentOS 7 中,所以需要先安装DNF。
# yum install epel-release
# yum install dnf
# dnf --version
一、问题:
CentOS7安装DNF后,运行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
其实最主要的错误就是最后一条:ImportError: No module named _conf
二、解决办法
- 先升级python:
yum update python*
- 再安装以下软件:
yum install dnf-data dnf-plugins-core libdnf-devel libdnf python2-dnf-plugin-migrate dnf-automatic -y
- 再次运行dnf,就正常了。
# dnf --version
4.0.9
Installed: dnf-0:4.0.9.2-1.el7_6.noarch at Fri 13 Nov 2020 05:40:22 AM EST
Built : CentOS BuildSystem <http://bugs.centos.org> at Wed 13 Feb 2019 08:19:33 PM EST
Installed: rpm-0:4.11.3-45.el7.x86_64 at Fri 13 Nov 2020 06:10:31 AM EST
Built : CentOS BuildSystem <http://bugs.centos.org> at Wed 30 Sep 2020 05:30:03 PM EST