Deleted the python binary, and can't recover using apt-get, what can I do?

In the future don't do this. Do not manually remove (or otherwise mess with) any files installed via package management tools (unless they are explicitly set up for this like configuration files, etc.).

That being said if you are unable (and it looks like this might be the case) to use apt-get to recover from this situation because there are parts of the process that expect that python is already installed then you have a few options (not all of which will necessarily work).

You can fetch the python (and related) .deb files manually and attmempt to use dpkg to install them manually (you'll need to resolve the dependency order manually to make sure this works correctly). Something like:

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*

You should check for other missing binaries, like pycompile, and apply the same solution.

After this, is recommendable to check the dpkg database looking for non configured, half-configured and just unpacked packages:

sudo dpkg --check

Read the messages and apply fixes, but normally it would ask for sudo dpkg --configure -a. An sudo apt-get -f install could help depending the situation.

You might also be able to use an installation media recovery mode (or reinstallation) to fix this.


Open a terminal and type the following commands:

First, try

sudo apt-get -f install 

If that doesn't work, try

sudo dpkg --configure -a 

If you are still left with problems, run

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

As a last resort, you might need to remove these packages with the following command and then reinstall these packages using the above command. If this is the case, you will need to pay very close attention. There will be a list of packages uninstalled with the following command. You will need to copy this list and paste it into gedit. With gedit open and the list of packages pasted into gedit, press ctrl + h and enter \n followed by two spaces in "Search for" and one space in "Replace with" to remove all the paragraphs and extra spaces before clicking replace all so that your list contains a list of packages separated only by single spaces.

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

Finally, run: sudo apt-get install and paste in the list of packages from gedit to reinstall everything.

Tags:

Python

Dpkg

Apt