Eliminé el binario de Python y no puedo recuperarlo usando apt-get, ¿qué puedo hacer?

11

Bien. Sí. Quería un nuevo comienzo porque estaba teniendo confusiones de dependencia, así que ejecuté "whereis python" y literalmente borré todos los archivos y directorios que aparecieron. Luego, cuando voy a ejecutar apt-get install python, por supuesto obtengo muchos errores. ¿Hay alguna manera de reinstalar python en ubuntu sin simplemente limpiarlo?

Aquí está el resultado de intentar instalar python binary:

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)

Después de seguir la ruta sugerida por 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)
pooley1994
fuente
python : Depends: python2.7 (>= 2.7.5-1~) but it is not going to be installed. Creo que tus conflictos de dependencia anteriores todavía te preocupan. ¿También puede dar salida dedpkg -l | grep python
cnvzmxcvmcx

Respuestas:

20

En el futuro no hagas esto. No elimine manualmente (ni se meta de otra manera) los archivos instalados a través de herramientas de administración de paquetes (a menos que estén configurados explícitamente para esto, como archivos de configuración, etc.).

Dicho esto, si no puede (y parece que este podría ser el caso) usar apt-getpara recuperarse de esta situación porque hay partes del proceso que esperan que Python ya esté instalado, entonces tiene algunas opciones (no todas necesariamente funcionará).

Puede buscar los .debarchivos de Python (y los relacionados) manualmente e intentar usarlos dpkgpara instalarlos manualmente (deberá resolver el orden de dependencia manualmente para asegurarse de que esto funcione correctamente). Algo como:

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*

Debe buscar otros binarios faltantes, como pycompile, y aplicar la misma solución.

Después de esto, es recomendable verificar la base de datos dpkg buscando paquetes no configurados, medio configurados y simplemente desempaquetados:

sudo dpkg --check

Lea los mensajes y aplique correcciones, pero normalmente lo solicitaría sudo dpkg --configure -a. Un sudo apt-get -f installpodría ayudar dependiendo de la situación.

También puede utilizar un modo de recuperación de medios de instalación (o reinstalación) para solucionar esto.

Etan Reisner
fuente
4

¿Hay alguna manera de reinstalar python en ubuntu sin simplemente limpiarlo?

Si. Vuelva a instalar sin formatear.

También será el método más rápido para solucionar esto, ya que probablemente ya tenga un DVD en vivo.

Rinzwind
fuente
3
Reinstalar ubuntu parece un poco exagerado en este caso.
ike
2
Dado que casi todo depende de python y "apt" ya no funcionará (debido a las dependencias de python), cualquier otro método llevará mucho más tiempo. Una reinstalación sin formato toma aproximadamente 10, 15 minutos en una máquina actual. @ike
Rinzwind
3
apt debería funcionar para otros paquetes, simplemente no para python. No es demasiado difícil solucionar esto reinstalando cada paquete.
ike
1
Eliminar un sistema binario puede ser catastrófico, pero no es el fin del mundo. Puede eliminarlo rmy recuperarlo fácilmente . Python es solo un paseo por el parque.
Braiam
1

Abra una terminal y escriba los siguientes comandos:

Primer intento

sudo apt-get -f install 

Si eso no funciona, intente

sudo dpkg --configure -a 

Si aún tiene problemas, ejecute

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

Como último recurso, es posible que deba eliminar estos paquetes con el siguiente comando y luego reinstalarlos utilizando el comando anterior. Si este es el caso, deberá prestar mucha atención. Habrá una lista de paquetes desinstalados con el siguiente comando. Deberá copiar esta lista y pegarla en gedit. Con gedit abierto y la lista de paquetes pegados en gedit, presione ctrl+ he ingrese \ n seguido de dos espacios en "Buscar" y un espacio en "Reemplazar por" para eliminar todos los párrafos y espacios adicionales antes de hacer clic en reemplazar todo para que su La lista contiene una lista de paquetes separados solo por espacios individuales.

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

Finalmente, ejecute: sudo apt-get instally pegue en la lista de paquetes de gedit para reinstalar todo.

mchid
fuente
Estoy casi seguro de que todos los paquetes python- * están incluidos en el metapaquete python. OP no necesitaría establecer y mantener una lista de paquetes para (des) / instalar. apt-get install --reinstall pythondebería cubrirlo.
amanthethy
@amanthethy, la "lista" que menciono es los cientos de otros paquetes que también se pueden desinstalar, como la unidad, todos los ámbitos, el administrador de cuentas, etc. Además, puedo nombrar algunos que no están incluidos, como python pip, por ejemplo .
mchid
1
No, no dañará a nadie, aparte del extraño túnel del carpelo, pero es innecesario. Además, python-pip es un administrador de paquetes para programas python. Es una aplicación creada con Python y no una característica del lenguaje en sí.
Amanthethy
1
sudo apt-get install --reinstall ubuntu-desktopcubrirá todos los extras que mencionaste. [unidad, ámbitos, python, gerente de cuentas, etc.]
amanthethy
1
No te preocupes amigo. Los votos negativos no significan mucho para mí siempre que podamos ayudar al OP :)
amanthethy
0

Debe eliminar cada paquete que le presente dificultades y luego reinstalarlos.

Consulte /ubuntu//a/32899/176376 para eliminarlo sin eliminar dependencias.

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

sudo apt-get install "package"

Primero debe eliminar todos los problemas y luego instalarlos nuevamente.

Ejecute todos sudo apt-get install -fy sudo dpkg --configure -acada uno de los comandos.

ike
fuente
0

Veo que tienes errores como este:

python2.7: not found

Significa que no se puede encontrar el ejecutable de Python 2.7. He usado estos comandos para encontrar el paquete que lo contiene (sin embargo, eso probablemente no funcionaría en su sistema dañado)

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

Debe reinstalarlo, pero primero debe pasar por sus dependencias. Use estos comandos para enumerarlos:

$ 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 probablemente esté dañado. Así que te recomiendo que primero publiques:

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

entonces:

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

y con suerte tu

sudo apt-get -f install

podría suceder.

usuario362066
fuente
-1

Ese es el comportamiento esperado. Eliminar archivos no es lo mismo que desinstalar un paquete o programa.

Has eliminado todas las cosas relacionadas con Python de tu instalación, pero tu administrador de paquetes no lo sabe. Cuando vuelva a instalar Python, apt espera que todos esos archivos sigan allí y no se molesta en volver a descargarlos. En lo que respecta a apt, toda Python todavía está instalada; Nunca lo dijiste de otra manera.

Puede intentar lo siguiente para intentar corregir esto:
sudo apt-get install --reinstall python

En el futuro, desinstalar paquetes utilizando apt-get removeo apt-get purgeo gráficamente desde el Centro de Software de Ubuntu.

amanthethy
fuente
3
Una purga de python desinstala muchas dependencias, donde la reinstalación no reinstalará todas esas.
oldfred
1
Tienes razón hasta el segundo párrafo. Su método de "corregir" el problema podría eliminar la mayoría de los paquetes del sistema OP.
Braiam
@Braiam Tienes razón. Di por sentado que apt-get remove package puede desinstalar paquetes que apt-get install package no necesariamente restaurará. He editado, pero siéntase libre de corregirlo si todavía estoy apagado.
Amanthethy