1. 问题现象
使用命令 sudo apt install python2.7
安装 Python2 时报如下错误
wohu@ubuntu1804:/etc/apt$ sudo apt install python2.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
python2.7 : Depends: python2.7-minimal (= 2.7.15~rc1-1) but it is not going to be installed
Depends: libpython2.7-stdlib (= 2.7.15~rc1-1) but 2.7.17-1~18.04ubuntu1 is to be installed
E: Unable to correct problems, you have held broken packages.
2. 解决方案
2.1 安装 aptitude
sudo apt-get install aptitude
2.2 使用 aptitude 安装 python2.7
sudo aptitude install python2.7
依次选择 n,y, y
wohu@ubuntu1804:/etc/apt$ sudo aptitude install python2.7
The following actions will resolve these dependencies:
Keep the following packages at their current version:
1) python2.7 [Not Installed]
2) python2.7-minimal [Not Installed]
Leave the following dependencies unresolved:
3) python2.7-minimal recommends python2.7
Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:
Downgrade the following packages:
1) libpython2.7 [2.7.17-1~18.04ubuntu1 (now) -> 2.7.15~rc1-1 (bionic)]
2) libpython2.7-minimal [2.7.17-1~18.04ubuntu1 (now) -> 2.7.15~rc1-1 (bionic)]
3) libpython2.7-stdlib [2.7.17-1~18.04ubuntu1 (now) -> 2.7.15~rc1-1 (bionic)]
Accept this solution? [Y/n/q/?] y
The following packages will be DOWNGRADED:
libpython2.7 libpython2.7-minimal libpython2.7-stdlib
The following NEW packages will be installed:
python2.7 python2.7-minimal{a}
0 packages upgraded, 2 newly installed, 3 downgraded, 0 to remove and 34 not upgraded.
Need to get 4,826 kB of archives. After unpacking 4,105 kB will be used.
Do you want to continue? [Y/n/?] y
3. aptitude 与 apt-get 的区别
aptitude
与 apt-get
一样,是 Debian
及其衍生系统中功能极其强大的包管理工具。与 apt-get
不同的是,aptitude
在处理依赖问题上更佳一些。
举例来说,aptitude
在删除一个包时,会同时删除本身所依赖的包。这样,系统中不会残留无用的包,整个系统更为干净。
有的问题 apt-get
解决不了,必须使用 aptitude
解决,有的问题,用 aptitude
解决不了,必须使用 apt-get
。
-
aptitude
解决得更好的地方:install
,remove
,reinstall
(apt-get无此功能), show(apt-get无此功能), search(apt-get无此功能), hold(apt-get无此功能), unhold(apt-get无此功能), -
apt-get
解决得更好的地方: source(aptitude无此功能), build-dep (低版本的aptitude没有build-dep功能) -
apt-get
跟aptitude
没什么区别的地方:update, upgrade (apt-get upgrade=aptitude safe-upgrade, apt-get dist-upgrade=aptitude full-upgrgade)