I run `sudo apt-get remove python2.7`, can I restore my Ubuntu now?

While reinstalling Ubuntu is probably the easiest way, it's worth pointing out that it's possible to recover without reinstalling everything.

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.)

In the future, if you need to reinstall a package, instead use

sudo apt-get install --reinstall python2.7

or

sudo aptitude reinstall python2.7

which reinstalls the package without having to remove the dependencies.


Removing Python is not a good idea as much of Ubuntu depends on it. You may have seen a warning telling you which packages depend on python and thus will be removed with Python. When proceeding you end up with a quite stripped down OS.

Reinstalling Ubuntu would now be the easiest and safest way to get it back. Take care not to delete your HOME when you do so.


If it's not too late for anyone, or if you have come across this problem lately, this is how I got it running:

I followed Mechanical snail's advice and downloaded all the packages using Synaptic. I selected all the relevant packages, basically everything with "python", "python2", "python3", "apt", "python-apt", etc., that was already installed in my computer, tagged them for reinstallation, and when I hit apply, I made sure I downloaded them only.

Then, under root, I went into the /var/cache/apt/archives folder and ran the following command to manually re-install everything I downloaded (you will see all the packages you downloaded with Synaptic in here):

dpkg --unpack *.deb

Anyway, I was getting this apt_pkg error whenever I would get an error message from a Python script in Aptana, and yesterday when I was trying to add a repo. Now at least I can add the repo with no problem, but I'm still getting the apt_pkg error whenever there is an error in my Python scripts...

Running the script outside of Aptana by calling python3.2 or python3 which points at 3.2 works (meaning I get the script's error without the apt_pkg error), but if I run it with python3.3 then the error is back.