I did a terrible mistake and deleted two folders from the /usr/lib directory on my Debian. I deleted python2.7/ and pkgconfig/

Things I've tried to fix it without success:

  • sudo dpkg -i python2* -> "could not find platform independent libraries" --> "/usr/lib/pyton2.7/py_compile.py no such file"

  • even deleting it (python; for future reinstalling) via sudo dpkg -i python2.7-minimal --> cant remove because python2.7-minimal depends on python2.7-minimal (>=... .deb) and python2.7 depends on python2.7-minimal (>=..._rc2.deb)

So I cant reinstall it or repair the packages as long they are not "configured" by dpkg as a apt-get install python says but also cant remove them for a clean reinstall since their are dependencies on different version in dpkg and I dont know how to solve this.

So how can I completely remove a packages with all dependencies via dpkg or apt to solve the described situation from above?

1 Answer 1


If apt is borked, sometimes it's possible to set things right manually with dpkg and the full path of the local cached package. Here's how:

  1. cd to where apt stores the packages, namely /var/cache/apt/archives/
  2. dpkg then (as needed) the switch for install, remove, purge or whatnot, then the filename of the package in the current directory. So to install one of several versions of 'foobar' that were successively installed recently, type dpkg -i foobar<TAB> and the '' key will fill in the rest with bash autocompletion, or show the available versions.
  3. If dpkg says you need 'fizban', (or must get rid of 'fizban'), do step #2, with 'fizban'. Then try step #2 with 'foobar' again.
  4. Repeat #2 & #3 until the system is in the desired state.

That assumes the package archives needed are still cached locally. Sometimes the packages need to be hunted down online. In which case the version number of the needed package might be somewhat uncertain -- in such cases, /var/log/dpkg.log has the answer, just grep or sed through that for the package name, and it'll show the versions dpkg has worked with so far.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .