删除了python二进制文件,并且无法使用apt-get恢复,该怎么办?


11

好。是的 想要重新开始,因为我遇到了依赖关系混乱,因此我运行了“ whereis python”并从字面上清除了所有出现的文件和目录。然后,当我去运行apt-get install python时,我当然会得到很多错误。有没有一种方法可以在ubuntu上重新安装python而不只是进行干净擦除?

这是尝试安装python二进制文件的输出:

root@ubuntu14-server:/home/kpoole# apt-get install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python is already the newest version.
The following packages were automatically installed and are no longer required:
libexpat1-dev libpython-dev libpython2.7-dev
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
15 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python-chardet (2.0.1-2build2) ...
/var/lib/dpkg/info/python-chardet.postinst: 6: /var/lib/dpkg/info/python-chardet.postinst: pycompile: not found
dpkg: error processing package python-chardet (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-colorama (0.2.5-0.1ubuntu1) ...
/var/lib/dpkg/info/python-colorama.postinst: 6: /var/lib/dpkg/info/python-colorama.postinst: pycompile: not found
dpkg: error processing package python-colorama (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-distlib (0.1.8-1) ...
/var/lib/dpkg/info/python-distlib.postinst: 6: /var/lib/dpkg/info/python-distlib.postinst: pycompile: not found
dpkg: error processing package python-distlib (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-django (1.6.1-2ubuntu0.5) ...
/var/lib/dpkg/info/python-django.postinst: 6: /var/lib/dpkg/info/python-django.postinst: pycompile: not found
dpkg: error processing package python-django (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-django-tables2:
python-django-tables2 depends on python-django (>= 1.4.5); however:
Package python-django is not configured yet.

dpkg: error processing package python-django-tables2 (--configure):
dependency problems - leaving unconfigured
Setting up python-six (1.5.2-1) ...
No apport report written because MaxReports is reached already
                                              /var/lib/dpkg/info/python-six.postinst: 6: /var/lib/dpkg/info/python-six.postinst: pycompile: not found
dpkg: error processing package python-six (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-html5lib:
python-html5lib depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-html5lib (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              Setting up python-lxml (3.3.3-1ubuntu0.1) ...
/var/lib/dpkg/info/python-lxml.postinst: 6: /var/lib/dpkg/info/python-lxml.postinst: pycompile: not found
dpkg: error processing package python-lxml (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              Setting up python-minimal (2.7.5-5ubuntu3) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-pkg-resources (3.3-1ubuntu1) ...
No apport report written because MaxReports is reached already
                                              /var/lib/dpkg/info/python-pkg-resources.postinst: 6: /var/lib/dpkg/info/python-pkg-resources.postinst: pycompile: not found
dpkg: error processing package python-pkg-resources (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-setuptools:
python-setuptools depends on python-pkg-resources (= 3.3-1ubuntu1); however:
Package python-pkg-resources is not configured yet.

dpkg: error processing package python-setuptools (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-urllib3:
python-urllib3 depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-urllib3 (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-requests:
python-requests depends on python-chardet; however:
Package python-chardet is not configured yet.
python-requests depends on python-urllib3 (>= 1.7.1); however:
Package python-urllib3 is not configured yet.

dpkg: error processing package python-requests (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-pip:
python-pip depends on python-colorama; however:
Package python-colorama is not configured yet.
python-pip depends on python-distlib; however:
Package python-distlib is not configured yet.
python-pip depends on python-html5lib; however:
Package python-html5lib is not configured yet.
python-pip depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-pip depends on python-setuptools (>= 0.6c1); however:
Package python-setuptools is not configured yet.
python-pip depends on python-six; however:
Package python-six is not configured yet.
python-pip depends on python-requests; however:
Package python-requests is not configured yet.

dpkg: error processing package python-pip (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-virtualenv:
python-virtualenv depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-virtualenv depends on python-setuptools; however:
Package python-setuptools is not configured yet.

dpkg: error processing package python-virtualenv (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              Errors were encountered while processing:
python-chardet
python-colorama
python-distlib
python-django
python-django-tables2
python-six
python-html5lib
python-lxml
python-minimal
python-pkg-resources
python-setuptools
python-urllib3
python-requests
python-pip
python-virtualenv
E: Sub-process /usr/bin/dpkg returned an error code (1)

经过ike建议的路线后:

root@ubuntu14-server:/home/kpoole# apt-get install --reinstall python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
python : Depends: python2.7 (>= 2.7.5-1~) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
root@ubuntu14-server:/home/kpoole# apt-get install -f
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:
libexpat1-dev libpython-dev libpython2.7-dev
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
python python2.7
Suggested packages:
python-doc python-tk python2.7-doc
The following NEW packages will be installed:
python python2.7
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
14 not fully installed or removed.
Need to get 0 B/330 kB of archives.
After this operation, 1,042 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package python2.7.
(Reading database ... 73738 files and directories currently installed.)
Preparing to unpack .../python2.7_2.7.6-8_amd64.deb ...
Unpacking python2.7 (2.7.6-8) ...
Selecting previously unselected package python.
Preparing to unpack .../python_2.7.5-5ubuntu3_amd64.deb ...
Unpacking python (2.7.5-5ubuntu3) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1) ...
Setting up python-minimal (2.7.5-5ubuntu3) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python2.7 (2.7.6-8) ...
/var/lib/dpkg/info/python2.7.postinst: 9: /var/lib/dpkg/info/python2.7.postinst: python2.7: not found
dpkg: error processing package 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.5-1~); however:
Package python2.7 is not configured yet.
python depends on python-minimal (= 2.7.5-5ubuntu3); however:
Package python-minimal is not configured yet.

dpkg: error processing package python (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-chardet:
python-chardet depends on python (>= 2.7); however:
Package python is not configured yet.
python-chardet depends on python (<< 2.8); however:
Package python is not configured yet.
python-chardet depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-chardet (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-colorama:
python-colorama depends on python (>= 2.7); however:
Package python is not configured yet.
python-coNo apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
        No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
                    lorama depends on python (<< 2.8); however:
Package python is not configured yet.
python-colorama depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-colorama (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-distlib:
python-distlib depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-distlib depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.

dpkg: error processing package python-distlib (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-django:
python-django depends on python (>= 2.7); however:
Package python is not configured yet.
python-django depends on python (<< 2.8); however:
Package python is not configured yet.
python-django depends on python:any (>= 2.7.1-0ubuntu2); however:
Package pythNo apport report written because MaxReports is reached already
on is not configured yet.

dpkg: error processing package python-django (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-django-tables2:
python-django-tables2 depends on python (>= 2.7); however:
Package python is not configured yet.
python-django-tables2 depends on python (<< 2.8); however:
Package python is not configured yet.
python-django-tables2 depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.
python-django-tables2 depends on python-django (>= 1.4.5); however:
Package python-django is not configured yet.

dpkg: error processing package python-django-tables2 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-six:
python-six depends on python (>= 2.7); however:
Package python is not configured yet.
python-six depends on python (<< 2.8); however:
Package python is not configured yet.
python-six depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-six (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-html5lib:
python-html5lib depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-html5lib depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-html5lib depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-html5lib (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-lxml:
python-lxml depends on python (>= 2.7); however:
Package python is not configured yet.
python-lxml depends on python (<< 2.8); however:
Package python is not configured yet.
python-lxml depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-lxml (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-pkg-resources:
python-pkg-resources depends on python:any (>= 2.7); however:
Package python is not configured yet.
python-pkg-resources depends on python:any (<< 2.8); however:
Package python is not configured yet.

dpkg: error processing package python-pkg-resources (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-setuptools:
python-setuptools depends on python:any (>= 2.7); however:
Package python is not configured yet.
python-setuptools depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-setuptools depends on python-pkg-resources (= 3.3-1ubuntu1); however:
Package python-pkg-resources is not configured yet.

dpkg: error processing package python-setuptools (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-urllib3:
python-urllib3 depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-urllib3 depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-urllib3 depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-urllib3 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-requests:
python-requests depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-requests depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-requests depends on python-chardet; however:
Package python-chardet is not configured yet.
python-requests depends on python-urllib3 (>= 1.7.1); however:
Package python-urllib3 is not configured yet.

dpkg: error processing package python-requests (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-pip:
python-pip depends on python (>= 2.7); however:
Package python is not configured yet.
python-pip depends on python (<< 2.8); however:
Package python is not configured yet.
python-pip depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.
python-pip depends on python-colorama; however:
Package python-colorama is not configured yet.
python-pip depends on python-distlib; however:
Package python-distlib is not configured yet.
python-pip depends on python-html5lib; however:
Package python-html5lib is not configured yet.
python-pip depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-pip depends on python-setuptools (>= 0.6c1); however:
Package python-setuptools is not configured yet.
python-pip depends on python-six; however:
Package python-six is not configured yet.
python-pip depends on python-requests; however:
Package python-requests is not c
dpkg: error processing package python-pip (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
python-minimal
python2.7
python
python-chardet
python-colorama
python-distlib
python-django
python-django-tables2
python-six
python-html5lib
python-lxml
python-pkg-resources
python-setuptools
python-urllib3
python-requests
python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)

python : Depends: python2.7 (>= 2.7.5-1~) but it is not going to be installed。我认为您以前的依赖冲突仍然困扰着您。您还可以给出dpkg -l | grep python
cnvzmxcvmcx的

Answers:


20

将来不要这样做。不要手动删除(或弄乱)通过软件包管理工具安装的任何文件(除非为此文件明确设置了这些文件,例如配置文件等)。

话虽这么说,如果您无法(似乎是这种情况)来apt-get从这种情况下恢复,因为该过程的某些部分期望已经安装了python,那么您就有几个选择(并非全部)一定可以)。

您可以.deb手动获取python(及相关)文件,然后尝试手动dpkg安装它们(您需要手动解决依赖关系顺序以确保其正确运行)。就像是:

apt-get download python2.7-minimal ## at least this package is necessary
sudo touch /usr/bin/python2.7 && sudo chmod +x /usr/bin/python2.7
sudo dpkg --unpack python2.7-minimal*

您应该检查其他缺少的二进制文件,例如pycompile,并应用相同的解决方案。

之后,建议检查dpkg数据库以查找未配置的,半配置的和刚刚解压缩的软件包:

sudo dpkg --check

阅读消息并应用修复程序,但通常会要求sudo dpkg --configure -a。一个sudo apt-get -f install可以依赖的情况有所帮助。

您也许还可以使用安装介质恢复模式(或重新安装)来解决此问题。


4

有没有一种方法可以在ubuntu上重新安装python而不只是进行干净擦除?

是。重新安装而不格式化。

由于您可能已经拥有Live DVD,因此它也是解决此问题的最快方法。


3
在这种情况下,重新安装ubuntu似乎有点过头了。
ike 2014年

2
由于几乎所有内容都依赖于python,并且“ apt”将不再起作用(由于python依赖性),因此任何其他方法都将花费更长的时间。在当前计算机上,无格式重新安装大约需要10、15分钟。@ike
Rinzwind 2014年

3
apt应该适用于其他软件包,而不是python。通过重新安装每个软件包来解决此问题并不难。
ike 2014年

1
删除系统二进制文件可能是灾难性的,但并不是世界末日。您可以rm轻松删除和恢复它Python只是在公园里散步。
Braiam 2014年

1

打开一个终端并输入以下命令:

第一次尝试

sudo apt-get -f install 

如果这不起作用,请尝试

sudo dpkg --configure -a 

如果仍然有问题,请运行

sudo apt-get install --reinstall python python-chardet python-colorama python-distlib python-django python-django-tables2 python-six python-html5lib python-lxml python-minimal python-pkg-resources python-setuptools python-urllib3 python-requests python-pip python-virtualenv

最后,您可能需要使用以下命令删除这些软件包,然后使用上述命令重新安装这些软件包。在这种情况下,您将需要非常注意。将显示使用以下命令卸载的软件包列表。您将需要复制此列表并将其粘贴到gedit中。打开gedit并粘贴到gedit中的软件包列表,按ctrl+ h并输入\ n,然后在“搜索”中输入两个空格,在“替换为”中删除一个空格,以删除所有段落和多余的空格,然后单击全部替换,这样您的list包含仅由单个空格分隔的软件包列表。

sudo apt-get purge python-chardet python-colorama python-distlib python-django python-django-tables2 python-six python-html5lib python-lxml python-minimal python-pkg-resources python-setuptools python-urllib3 python-requests python-pip python-virtualenv

最后,运行:sudo apt-get install并粘贴gedit的软件包列表以重新安装所有内容。


我几乎可以确定所有python- *软件包都包含在python meta-package中。OP无需建立和维护要(取消)/安装的软件包的列表。apt-get install --reinstall python应该覆盖它。
amanthethy 2014年

@amanthethy我提到的“列表”是数百个其他软件包,也可能会被卸载,例如unity,所有作用域,客户经理等。此外,我还可以列举一些未包含的软件包,例如python pip 。
mchid 2014年

1
不,除了奇怪的心皮隧道外,它不会伤害任何人,但这是不必要的。另外,python-pip是python程序的软件包管理器。它是使用python构建的应用程序,而不是语言本身的功能。
amanthethy 2014年

1
sudo apt-get install --reinstall ubuntu-desktop将涵盖您提到的所有这些额外费用。[单位,范围,python,客户经理等]
amanthethy 2014年

1
不用担心,伙计。只要我们能够帮助OP
Downvotes

0

您应该删除每个给您带来麻烦的软件包,然后重新安装它们。

请参阅/ubuntu//a/32899/176376,以删除而不删除依赖项。

sudo dpkg -r --force-depends "package"

sudo apt-get install "package"

您应该先删除所有问题,然后再重新安装。

运行sudo apt-get install -fsudo dpkg --configure -a每隔几个命令。


0

我看到您有这样的错误:

python2.7: not found

这意味着找不到python 2.7可执行文件。我已经使用这些命令来找到包含它的软件包(但是,这可能在损坏的系统上不起作用)

$ which python2.7
/usr/bin/python2.7
$ dpkg -S /usr/bin/python2.7
python2.7-minimal: /usr/bin/python2.7

您需要重新安装它,但是首先您需要检查其依赖性。使用以下命令列出它们:

$ apt-cache depends python2.7-minimal
python2.7-minimal
  Depends: libpython2.7-minimal
  Depends: zlib1g
  PreDepends: libc6
  Suggests: binfmt-support
    binfmt-support:i386
  Recommends: python2.7
  Conflicts: binfmt-support
  Conflicts: binfmt-support:i386
  Replaces: python2.7
  Replaces: python2.7:i386
  Conflicts: python2.7-minimal:i386

libpython2.7-minimal可能已损坏。因此,我建议您首先发布:

sudo apt-get install --reinstall libpython2.7-minimal

然后:

sudo apt-get install --reinstall python2.7-minimal

然后希望你

sudo apt-get -f install

将会成功。


-1

这是预期的行为。删除文件与卸载程序包或程序不同。

您已从安装中删除了所有与python相关的内容,但包管理器不知道这一点。当您再次安装Python时,apt希望所有这些文件都仍然存在,并且不必费心尝试重新下载它们。就apt而言,仍然安装了所有python。你从来没有告诉过它。

您可以尝试以下方法来纠正此问题:
sudo apt-get install --reinstall python

在未来,卸载软件包使用apt-get removeapt-get purge或图形从Ubuntu软件中心。


3
清除python会卸载大量依赖项,其中重新安装不会重新安装所有依赖项。
2014年

1
您是正确的,直到第二段。您“纠正”问题的方法可能只会删除大多数OP系统软件包。
Braiam 2014年

@布赖恩你是对的。我认为apt-get remove软件包可以卸载不一定会还原apt-get install软件包的软件包。我已经编辑过,但是如果我仍然不在,请随时进行更正。
amanthethy
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.