我尝试在 ubuntu 上使用 apt-get 安装一些软件包,但其中几个软件包出现了类似的错误。看来我的 python 软件包出了问题,因为我收到消息“您持有损坏的软件包”。
~$ sudo apt-get install ranger 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: ranger : Depends: python:any (< 2.8)
Depends: python:any (>= 2.7.5-5~)
Recommends: python-chardet but it is not going to be installed E: Unable to correct problems, you have held broken packages.
~$ python -V
Python 2.7.13
~$ python3 -V
Python 3.5.2
dpkg --get-selections | grep hold
没有给我任何信息,所以我似乎找不到被保存的内容。与上面的输出一样,ubuntu 自带的 python 2 和我安装的 python 3 都在那里,但我仍然收到错误。这是我安装 python 不当的症状吗,还是有其他解决方法?
答案1
问题似乎是我手动将 Python 安装到比发行版提供的版本更新的版本。当 apt-get 尝试修复安装时,它需要降级,这只有在您指定它应该降级时才有可能。
/etc/apt/preferences.d/allow-downgrade
创建包含以下内容的文件
Package: *
Pin: release o=Ubuntu
Pin-Priority: 1001
然后运行
apt-get update
apt-get upgrade
apt-get -f install
apt-get update
解决了问题。
欲了解来源和更详细的答案: