Rui
Rui

Reputation: 3667

How to recover /usr/bin/python on Debian when removed by accident

On my Debian system, I removed /usr/bin/python and /usr/bin/python2.7 by accident. Then I tried to remove all of Python entirely with the apt-get remove command and installed it again. Unfortunately, /usr/bin/python was not created again as I expected.

As a result, the python command cannot be run anymore. So I would like to recover the /usr/bin/python2.7 on the OS level.

Moreover, when I restart the Debian system, even the GNOME GUI can't be launched anymore; only the tty terminal 8 was available, almost certainly because of the absence of /usr/bin/python.

Upvotes: 1

Views: 1161

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123730

/usr/bin/python is part of the python-minimal package and /usr/bin/python2.7 is contained in python2.7-minimal, reinstall those packages:

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

You can always ask your package manager what package to reinstall, dpkg -S lets you search for what package owns a given file:

$ dpkg --help | grep -- -S
  -S|--search <pattern> ...        Find package(s) owning file(s).
$ dpkg -S /usr/bin/python /usr/bin/python2.7
python-minimal: /usr/bin/python
python2.7-minimal: /usr/bin/python2.7

or you can use the Debian package web interface.

If apt-get install still fails with errors, then the package scripts could well be requiring Python to still work. Your next step is to then download the .deb files manually and copy those into place until you can run the apt-get install.

Determine your system architecture:

$ dpkg --print-architecture amd64

then visit the python2.7-minimal and python-minimal package pages; on each page click on the matching architecture link under the Download header. You are taken to a list of mirrors. Download a copy of the .deb files from a suitable mirror or copy the URL to use curl -O <url> to download it directly to your affected computer.

Then unpack those files with:

$ mkdir /tmp/rescue
$ dpkg-deb -x python-minimal_*.deb rescue
$ dpkg-deb -x python2.7-minimal_*_amd64.deb rescue

You can now copy the required files from /tmp/rescue/usr/bin to your system.

Upvotes: 7

Related Questions