无法升级或删除损坏的 VirtualBox 软件包

无法升级或删除损坏的 VirtualBox 软件包

我首先来介绍一下导致这一事件的一些细节:

  • 我正在使用 Ubuntu 14.0(上面是 KDE,虽然这可能不相关)
  • 几天前我让系统自动升级。
  • 尝试更新 Virtualbox 时,它在中途崩溃了,我认为这是因为我当时正在运行它。(我没有收到它给出的错误)
  • 我耸耸肩,说:“去你的吧,以后再处理。”
  • 今天停电了,当我尝试重新启动任何虚拟机时,却收到错误。遗憾的是,我没有收到该错误。我认为在我尝试修复它时,该软件包已经彻底损坏。我甚至找不到该程序,更不用说运行它了。

但是现在,我在修复甚至删除软件包时遇到了问题。为简洁起见,我不会在这里包含完整的控制台输出 - 只包含错误。如果需要,我当然可以添加更多。

因此首先,我执行了 apt-get upgrade,并得到了以下结果:

You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 virtualbox-dkms : Depends: virtualbox (>= 4.3.18-dfsg-2ubuntu1) but 4.3.18-dfsg-1 is installed
 virtualbox-qt : Depends: virtualbox (= 4.3.18-dfsg-2ubuntu1) but 4.3.18-dfsg-1 is installed

根据 apt-get 输出的建议,我这样做了:

apt-get -f install

并得到:

Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.16.0-23 linux-headers-3.16.0-23-generic
  linux-image-3.16.0-23-generic linux-image-extra-3.16.0-23-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  virtualbox
Suggested packages:
  vde2 virtualbox-guest-additions-iso
The following packages will be upgraded:
  virtualbox

...

Preparing to unpack .../virtualbox_4.3.18-dfsg-2ubuntu1_amd64.deb ...           
  File "/usr/bin/pyclean", line 63                                              
    except (IOError, OSError), e:                                               
                             ^                                                  
SyntaxError: invalid syntax                                                     
dpkg: warning: subprocess old pre-removal script returned error exit status 1   
dpkg: trying script from the new package instead ...                            
  File "/usr/bin/pyclean", line 63                                              
    except (IOError, OSError), e:                                               
                             ^                                                  
SyntaxError: invalid syntax                                                     
dpkg: error processing archive /var/cache/apt/archives/virtualbox_4.3.18-dfsg-2ubuntu1_amd64.deb (--unpack):                                                    
 subprocess new pre-removal script returned error exit status 1                 
Traceback (most recent call last):                                              
  File "/usr/bin/pycompile", line 35, in <module>                               
    from debpython.version import SUPPORTED, debsorted, vrepr, \                
  File "/usr/share/python/debpython/version.py", line 24, in <module>           
    from ConfigParser import SafeConfigParser                                   
ImportError: No module named 'ConfigParser'
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/virtualbox_4.3.18-dfsg-2ubuntu1_amd64.deb

现在,我不是 Python 专家,但我想至少尝试一下,看看我是否可以通过移动这些行括号内的“,e”来修复这些语法错误。当我更改上面提到的那个时,我在 /usr/share/python/debpython/namespace.py 中的一行上得到了同样的错误。我也更改了它,然后得到了这个错误:

root@gonzo:~# apt-get -f remove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  dkms linux-headers-3.16.0-23 linux-headers-3.16.0-23-generic
  linux-image-3.16.0-23-generic linux-image-extra-3.16.0-23-generic
  virtualbox-dkms
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  virtualbox
Suggested packages:
  vde2 virtualbox-guest-additions-iso
The following packages will be upgraded:
  virtualbox
1 upgraded, 0 newly installed, 0 to remove and 98 not upgraded.
129 not fully installed or removed.
Need to get 0 B/15.9 MB of archives.
After this operation, 17.4 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 209565 files and directories currently installed.)
Preparing to unpack .../virtualbox_4.3.18-dfsg-2ubuntu2_amd64.deb ...
Traceback (most recent call last):
  File "/usr/bin/pyclean", line 32, in <module>
    from debpython.namespace import add_namespace_files
  File "/usr/share/python/debpython/namespace.py", line 28, in <module>
    from debpython.pydist import PUBLIC_DIR_RE
  File "/usr/share/python/debpython/pydist.py", line 27, in <module>
    from string import maketrans
ImportError: cannot import name 'maketrans'
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 32, in <module>
    from debpython.namespace import add_namespace_files
  File "/usr/share/python/debpython/namespace.py", line 28, in <module>
    from debpython.pydist import PUBLIC_DIR_RE
  File "/usr/share/python/debpython/pydist.py", line 27, in <module>
    from string import maketrans
ImportError: cannot import name 'maketrans'
dpkg: error processing archive /var/cache/apt/archives/virtualbox_4.3.18-dfsg-2ubuntu2_amd64.deb (--unpack):
 subprocess new pre-removal script returned error exit status 1
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/virtualbox_4.3.18-dfsg-2ubuntu2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

这时我意识到我走错了路,并撤销了对上述文件的更改。

然后我(当时真的不知道自己在做什么,只是猜测事情是如何运作的)尝试将 /var/cache/apt/virtualbox* 移到另一个目录并再次运行它。当然,这没有用,所以我把它们移回来了。

所以我打开 Synaptic 尝试修复它。但还是没用。如果我将软件包标记为要删除,就会出现此错误

E: virtualbox: package is in a very bad inconsistent state; you should  reinstall it before attempting a removal

但是我无法遵循这些说明,因为“标记为重新安装”选项是灰色的。

Synaptic 尝试的整个控制台输出如下:

(synaptic:21937): GLib-CRITICAL **: g_child_watch_add_full: assertion 'pid > 0' failed
dpkg: error processing package virtualbox (--purge):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
Errors were encountered while processing:
 virtualbox
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install.  Trying to recover:

而此时我完全不知所措。有人能帮我摆脱困境吗?

答案1

好的,如果有人碰巧遇到这个问题,我的老板就设法解决了:

我运行的 Python 版本不对。从 Python 3.4 切换回 Python 2.7.8 后,问题得到解决。

相关内容