How to restore after accidentally apt-get remove python
Question:
Yeah. I’ve done this. It was stupid.
I did not know it’s going to take its dependencies with itself, only wanted to install python 2 and 3 from scratch (because of this problem: https://askubuntu.com/questions/897355/how-to-change-default-idle-for-python).
Now, I can still use my terminal, checked these answers:
https://askubuntu.com/questions/741265/apt-get-remove-python-150mb-apt-get-install-python-687kb
https://askubuntu.com/questions/437644/i-accidentaly-did-sudo-apt-get-remove-python
However after running sudo apt-get install ubuntu-desktop
I get these errors:
Setting up python-ldb (2:1.1.24-1ubuntu3) ...
/var/lib/dpkg/info/python-ldb.postinst: 6: /var/lib/dpkg/info/python-ldb.postinst: pycompile: not found
dpkg: error processing package python-ldb (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
Setting up python-tdb (1.3.8-2) ...
/var/lib/dpkg/info/python-tdb.postinst: 6: /var/lib/dpkg/info/python-tdb.postinst: pycompile: not found
dpkg: error processing package python-tdb (--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-samba:
python-samba depends on python-crypto; however:
Package python-crypto is not configured yet.
python-samba depends on python-ldb (>= 1.1.2~); however:
Package python-ldb is not configured yet.
python-samba depends on python-tdb; however:
Package python-tdb is not configured yet.
dpkg: error processing package python-samba (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Errors were encountered while processing:
mercurial-common
python-crypto
python-dnspython
python-ldb
python-tdb
python-samba
E: Sub-process /usr/bin/dpkg returned an error code (1)
Every apt-get install command throws this.
Is there a way to restore these dependencies?
Answers:
To do this, manually download the python2.7 package (and its dependencies), and manually install them using dpkg (bypassing APT, which requires Python). Once that’s installed, apt should work again, and so apt-get install ubuntu-desktop will restore your system. (If apt-get still doesn’t work, you might also need to download and install any missing dependencies.)
Dose that work?
Hallelujah.
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
sudo apt-get install --reinstall python-dnspython
sudo apt autoremove
sudo apt-get -f install
After a whole day of adventures in the deepest pits of internet, these commands worked for me.
python-dnspython and samba was still missing after the first command, --reinstall python-dnspython
pulled samba in as well. Autoremove removed the needless dependencies.
Naturally some of these could be quite redundant but I was just following some long lost forum posts all over the place and what matters is that it worked.
you can restore everything again by just running
sudo apt install gnome
even if you left with kernal only
I did the following and was able to recover my system fully:
1) sudo apt-get update
2) Ran the 4 commands given above by MattSom (thanks to him):
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
sudo apt-get install --reinstall python-dnspython
sudo apt autoremove
sudo apt-get -f install
But GUI was still not available. I run below to recover that as well:
3) sudo apt-get install --reinstall ubuntu-desktop
For me this
sudo apt-get install --reinstall python3 python3-chardet python3-colorama python3-distlib python3-django python3-django-tables2 python3-six python3-html5lib python3-lxml python3-minimal python3-pkg-resources python3-setuptools python3-urllib3 python3-requests python3-pip python3-virtualenv
sudo apt-get install --reinstall python-dnspython // this was needed
sudo apt autoremove // there was nothing to autoremove
sudo apt-get -f install // there was nothing dependences.
wasn’t enough.
I had to run first this line, because my internet connection was broken
sudo dhclient -r;sudo dhclient
Then run previous block and then this
sudo apt-get install ubuntu-minimal ubuntu-desktop
And after all this I had to reinstall my NVIDIA drivers.
For me what worked was to find and fix the Broken Packages on my PC
sudo apt --fix-missing update
sudo apt update
sudo apt install -f
Try this of Ubuntu 20.04+ versions:
sudo apt-get update
sudo apt-get install --reinstall python3 python3-chardet python3-colorama python3-distlib python3-django python3-django-tables2 python3-six python3-html5lib python3-lxml python3-minimal python-pkg-resources python-setuptools python3-urllib3 python3-requests python3-pip python3-virtualenv
sudo apt-get install --reinstall python3-dnspython
sudo apt autoremove
sudo apt-get -f install
sudo apt-get install --reinstall ubuntu-desktop
reboot
If your ubuntu is stuck on login screen with no response from Keyboard or Mouse, then try this:
Reboot -> Advanced Options for Ubuntu -> recovery mode -> network
-> Yes -> again recovery options will come now select root -> terminal will get started
Run the above commands and it will work.
Yeah. I’ve done this. It was stupid.
I did not know it’s going to take its dependencies with itself, only wanted to install python 2 and 3 from scratch (because of this problem: https://askubuntu.com/questions/897355/how-to-change-default-idle-for-python).
Now, I can still use my terminal, checked these answers:
https://askubuntu.com/questions/741265/apt-get-remove-python-150mb-apt-get-install-python-687kb
https://askubuntu.com/questions/437644/i-accidentaly-did-sudo-apt-get-remove-python
However after running sudo apt-get install ubuntu-desktop
I get these errors:
Setting up python-ldb (2:1.1.24-1ubuntu3) ...
/var/lib/dpkg/info/python-ldb.postinst: 6: /var/lib/dpkg/info/python-ldb.postinst: pycompile: not found
dpkg: error processing package python-ldb (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
Setting up python-tdb (1.3.8-2) ...
/var/lib/dpkg/info/python-tdb.postinst: 6: /var/lib/dpkg/info/python-tdb.postinst: pycompile: not found
dpkg: error processing package python-tdb (--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-samba:
python-samba depends on python-crypto; however:
Package python-crypto is not configured yet.
python-samba depends on python-ldb (>= 1.1.2~); however:
Package python-ldb is not configured yet.
python-samba depends on python-tdb; however:
Package python-tdb is not configured yet.
dpkg: error processing package python-samba (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Errors were encountered while processing:
mercurial-common
python-crypto
python-dnspython
python-ldb
python-tdb
python-samba
E: Sub-process /usr/bin/dpkg returned an error code (1)
Every apt-get install command throws this.
Is there a way to restore these dependencies?
To do this, manually download the python2.7 package (and its dependencies), and manually install them using dpkg (bypassing APT, which requires Python). Once that’s installed, apt should work again, and so apt-get install ubuntu-desktop will restore your system. (If apt-get still doesn’t work, you might also need to download and install any missing dependencies.)
Dose that work?
Hallelujah.
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
sudo apt-get install --reinstall python-dnspython
sudo apt autoremove
sudo apt-get -f install
After a whole day of adventures in the deepest pits of internet, these commands worked for me.
python-dnspython and samba was still missing after the first command, --reinstall python-dnspython
pulled samba in as well. Autoremove removed the needless dependencies.
Naturally some of these could be quite redundant but I was just following some long lost forum posts all over the place and what matters is that it worked.
you can restore everything again by just running
sudo apt install gnome
even if you left with kernal only
I did the following and was able to recover my system fully:
1) sudo apt-get update
2) Ran the 4 commands given above by MattSom (thanks to him):
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
sudo apt-get install --reinstall python-dnspython
sudo apt autoremove
sudo apt-get -f install
But GUI was still not available. I run below to recover that as well:
3) sudo apt-get install --reinstall ubuntu-desktop
For me this
sudo apt-get install --reinstall python3 python3-chardet python3-colorama python3-distlib python3-django python3-django-tables2 python3-six python3-html5lib python3-lxml python3-minimal python3-pkg-resources python3-setuptools python3-urllib3 python3-requests python3-pip python3-virtualenv
sudo apt-get install --reinstall python-dnspython // this was needed
sudo apt autoremove // there was nothing to autoremove
sudo apt-get -f install // there was nothing dependences.
wasn’t enough.
I had to run first this line, because my internet connection was broken
sudo dhclient -r;sudo dhclient
Then run previous block and then this
sudo apt-get install ubuntu-minimal ubuntu-desktop
And after all this I had to reinstall my NVIDIA drivers.
For me what worked was to find and fix the Broken Packages on my PC
sudo apt --fix-missing update
sudo apt update
sudo apt install -f
Try this of Ubuntu 20.04+ versions:
sudo apt-get update
sudo apt-get install --reinstall python3 python3-chardet python3-colorama python3-distlib python3-django python3-django-tables2 python3-six python3-html5lib python3-lxml python3-minimal python-pkg-resources python-setuptools python3-urllib3 python3-requests python3-pip python3-virtualenv
sudo apt-get install --reinstall python3-dnspython
sudo apt autoremove
sudo apt-get -f install
sudo apt-get install --reinstall ubuntu-desktop
reboot
If your ubuntu is stuck on login screen with no response from Keyboard or Mouse, then try this:
Reboot -> Advanced Options for Ubuntu -> recovery mode -> network
-> Yes -> again recovery options will come now select root -> terminal will get started
Run the above commands and it will work.