如何使用 apt-get 在我的 Ubuntu 12.04 服务器上重新安装 python?

Phi*_*unt 6 python apt

因为我完全搞砸了我的 python 安装,所以我手动删除了所有 python 文件,现在正在尝试重新安装它。

当我输入时apt-get install --reinstall python2.7,我收到此错误消息:

0 to upgrade, 0 to newly install, 1 reinstalled, 0 to remove and 0 not to upgrade.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up python-minimal (2.7.3-0ubuntu2.2) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found
dpkg: error processing python-minimal (--configure):
 subprocess installed post-installation script returned error exit status 127
Setting up python2.7 (2.7.3-0ubuntu3.4) ...
/var/lib/dpkg/info/python2.7.postinst: 6: /var/lib/dpkg/info/python2.7.postinst:     
 python2.7: not found
dpkg: error processing python2.7 (--configure):
 subprocess installed post-installation script returned error exit status 127
dpkg: dependency problems prevent configuration of python:
 python depends on python2.7 (>= 2.7.3); however:
  Package python2.7 is not configured yet.
  python depends on python-minimal (= 2.7.3-0ubuntu2.2); however:
  Package python-minimal is not configured yet.
dpkg: error processing python (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates it's a follow-up error from a previous failure.
                                                                                                        Errors were encountered while processing:
 python-minimal
 python2.7
 python
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

我该如何从中恢复?

编辑:根据kubahaha的建议,我尝试了

# dpkg -P python2.7
Run Code Online (Sandbox Code Playgroud)

由于依赖关系,它不起作用。这确实删除了软件包:

# dpkg -P libapache2-mod-wsgi libpython2.7 python2.7
Run Code Online (Sandbox Code Playgroud)

但是当我尝试时:

# apt-get install python2.7 libapache2-mod-wsgi libpython2.7
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found                                                                         
dpkg: error processing python-minimal (--configure):                                        
 subprocess installed post-installation script returned error exit status 127               
Errors were encountered while processing:
 python-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

dpkg/apt 在我看来非常脆弱,因为一旦系统处于不良状态,它们似乎永远无法将自己恢复到良好状态。

kub*_*aha 1

清除然后重新安装

  1. sudo dpkg -P python2.7
  2. sudo apt-get install python2.7

  • @kubahaha:好吧,我刚刚学会了不要在不理解的情况下盲目复制命令。我刚刚把我的 ubuntu 变砖了,因为显然所有 ubuntu 软件包都依赖于 python,并且 `sudo apt-get autoremove` 删除了所有内容 =( (3认同)