我确实需要一些帮助来弄清楚如何处理这个问题,但是在修复之前我无法升级我的服务器:
sudo apt -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
apport debconf
Suggested packages:
apport-gtk | apport-kde debconf-doc debconf-utils libterm-readline-gnu-perl libgtk2-perl
libnet-ldap-perl libqtgui4-perl libqtcore4-perl
The following packages will be upgraded:
apport debconf
2 upgraded, 0 newly installed, 0 to remove and 225 not upgraded.
31 not fully installed or removed.
Need to get 257 kB of archives.
After this operation, 4,096 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 debconf all 1.5.58ubuntu2 [136 kB]
Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 apport all 2.20.1-0ubuntu2.21 [121 kB]
Fetched 257 kB in 0s (16.3 MB/s)
Preconfiguring packages ...
(Reading database ... 163132 files and directories currently installed.)
Preparing to unpack .../debconf_1.5.58ubuntu2_all.deb ...
Traceback (most recent call last):
File "/usr/bin/pyclean", line 24, in <module>
import logging
File "/usr/bin/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/usr/bin/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
dpkg: warning: subprocess old pre-removal script returned error exit status 1
dpkg: trying script from the new package instead ...
Traceback (most recent call last):
File "/usr/bin/pyclean", line 24, in <module>
import logging
File "/usr/bin/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/usr/bin/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
dpkg: error processing archive /var/cache/apt/archives/debconf_1.5.58ubuntu2_all.deb (--unpack):
subprocess new pre-removal script returned error exit status 1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 26, in <module>
import logging
File "/usr/bin/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/usr/bin/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
/var/cache/apt/archives/debconf_1.5.58ubuntu2_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
在 EC2 micro 上。有什么想法吗?
更新:我很感谢@FlorianDiesch 在下面的评论。这是正确的评估。我肯定安装了一个单独的 python 版本(我得补充一下,安装得很糟糕),这个版本在 中有内容/usr/bin/lib
。所以我删除了所有有问题的文件,并清理了我的.bashrc
,这增加了混乱,因为导出了对它们的引用。删除完所有文件后,我将 2.7 和 3.5 的发行版添加到update-alternatives
:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
将 2.7 设置为默认值。
重新安装pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
然后参加apt:
sudo apt -f install
sudo apt update
sudo apt upgrade
世界一切都好……只是我沮丧地删除了一个需要花一秒钟才能恢复的配置文件。哦,好吧。
答案1
选项 1:重新配置包数据库
可能是安装包时数据库损坏了。重新配置可以修复该问题。
sudo dpkg --configure -a
选项 2:删除有问题的软件包的 post 信息文件
尝试从中删除与有问题的包相关的文件/var/lib/dpkg/info
。
从你的终端输出来看,这似乎debconf
引起了问题
ls -l /var/lib/dpkg/info | grep -i debconf
现在,只需删除这些文件(或者将它们移动到另一个位置):
sudo mv /var/lib/dpkg/info/debconf.* /tmp