How to fix unmet dependencies after removing python?

8,098

Solution 1

You can fix the issue if you have access to some ubuntu VPS that is working fine:

apt download python2.7-minimal libpython2.7-stdlib python2.7

Then you have to copy the essential files to your own system with:

sudo scp you@yourserver:/usr/lib/python2.7/*.py /usr/lib/python2.7/
sudo scp -r you@yourserver:/usr/lib/python2.7/plat-x86_64-linux-gnu /usr/lib/python2.7/
sudo scp -r you@yourserver:/usr/lib/python2.7/logging /usr/lib/python2.7/
sudo scp -r you@yourserver:/usr/lib/python2.7/encodings /usr/lib/python2.7/

Then you should use dpkg for installing python:

sudo dpkg -i python2.7-minimal_2.7.12-1ubuntu0~16.04.2_amd64.deb libpython2.7-stdlib_2.7.12-1ubuntu0~16.04.2_amd64.deb python2.7_2.7.12-1ubuntu0~16.04.2_amd64.deb

Then you should let apt take care of everything itself:

sudo apt-get install -f

Then You can verify that apt is working fine with:

sudo apt upgrade

Solution 2

Essential system services (like apt) depend upon Python, so it's likely that your system is now very badly broken.

You have two choices:

  • You can manually reinstall each python package using dpkg
  • You can back up your data and do a clean install.

The first choice is likely to be fast and fairly easy for skilled users. The second choice is likely to be faster and easier for most regular users.

Share:
8,098
yukashima huksay
Author by

yukashima huksay

Apparently, that user prefers to keep an air of mystery about them.

Updated on September 18, 2022

Comments

  • yukashima huksay
    yukashima huksay over 1 year

    I was struggling so much to install an application. And somewhere in comments someone had said I went brutal and did rm -rf /usr/lib/python2.7 and then I did the same. And after that I did sudo apt purge python2.7-minimal now my system is completely broken for example when I do sudo apt upgrade I get:

    The following packages have unmet dependencies:
     gimp : Depends: python:any (>= 2.6.6-7~)
     libboost-mpi-python1.58.0 : Depends: python (< 2.8) but it is not installed
                                 Depends: python (>= 2.7~) but it is not installed
                                 Depends: python:any (>= 2.7.5-5~)
     libboost-python1.58-dev : Depends: python-dev but it is not installed
                               Depends: python:any (< 2.8)
                               Depends: python:any (>= 2.7.5-5~)
                               Depends: python (>= 2.5) but it is not installed or
                                        python-celementtree but it is not installable or
                                        python-elementtree but it is not installable
     ndiff : Depends: python:any (< 2.8)
             Depends: python:any (>= 2.7.5-5~)
     python-bs4 : Depends: python:any (< 2.8)
                  Depends: python:any (>= 2.7.5-5~)
     python-cairo : Depends: python (< 2.8) but it is not installed
                    Depends: python (>= 2.7~) but it is not installed
                    Depends: python:any (>= 2.7.5-5~)
     python-chardet : Depends: python:any (< 2.8)
                      Depends: python:any (>= 2.7.5-5~)
                      Depends: python-pkg-resources but it is not installed
     python-dbus : Depends: python (< 2.8) but it is not installed
                   Depends: python (>= 2.7~) but it is not installed
                   Depends: python:any (>= 2.7.5-5~)
     python-gi : Depends: python (< 2.8) but it is not installed
                 Depends: python (>= 2.7~) but it is not installed
                 Depends: python:any (>= 2.7.5-5~)
     python-gobject-2 : Depends: python (< 2.8) but it is not installed
                        Depends: python (>= 2.7~) but it is not installed
                        Depends: python:any (>= 2.7.5-5~)
     python-gtk2 : Depends: python (>= 2.7) but it is not installed
                   Depends: python (< 2.8) but it is not installed
     python-html5lib : Depends: python-six but it is not installed
                       Depends: python:any (< 2.8)
                       Depends: python:any (>= 2.7.5-5~)
     python-lxml : Depends: python (>= 2.7) but it is not installed
                   Depends: python (< 2.8) but it is not installed
     python-pip : Depends: python:any (< 2.8)
                  Depends: python:any (>= 2.7.5-5~)
                  Recommends: python-all-dev (>= 2.6) but it is not installed
     python-setuptools : Depends: python-pkg-resources (= 20.7.0-1) but it is not installed
                         Depends: python:any (< 2.8)
                         Depends: python:any (>= 2.7.5-5~)
     python-wheel : Depends: python:any (< 2.8)
                    Depends: python:any (>= 2.7.5-5~)
     python-xlib : Depends: python:any (< 2.8)
                   Depends: python:any (>= 2.7.5-5~)
     speedtest-cli : Depends: python (>= 2.7) but it is not installed
                     Depends: python (< 2.8) but it is not installed
                     Depends: python-pkg-resources but it is not installed
    

    And when I issue sudo apt-get -f install I get:

    The following additional packages will be installed:
      python python-dev python-pkg-resources python-six python2.7-dev
    Suggested packages:
      python-doc python-tk
    The following NEW packages will be installed:
      python python-dev python-pkg-resources python-six python2.7-dev
    0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
    21 not fully installed or removed.
    Need to get 0 B/533 kB of archives.
    After this operation, 1,465 kB of additional disk space will be used.
    Do you want to continue? [Y/n] Y
    Setting up python2.7-minimal (2.7.12-1ubuntu0~16.04.2) ...
    Could not find platform independent libraries <prefix>
    Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
    python2.7: can't open file '/usr/lib/python2.7/py_compile.py': [Errno 2] No such file or directory
    dpkg: error processing package python2.7-minimal (--configure):
     subprocess installed post-installation script returned error exit status 2
    dpkg: dependency problems prevent configuration of python-minimal:
     python-minimal depends on python2.7-minimal (>= 2.7.11-1~); however:
      Package python2.7-minimal is not configured yet.
    
    dpkg: error processing package python-minimal (--configure):
     dependency problems - leaving unconfigured
    No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                              Errors were encountered while processing:
     python2.7-minimal
     python-minimal
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    

    What should I do now!? How can I fix what I've ruined!?

  • tgwtdt
    tgwtdt over 6 years
    another good way would be to copy the whole python directory but what I've provided is the minimal way to fix it. otherwise it will take some time because there can be some many files to copy and in that case you'd better compress everything first and then move it to your system and decompress it.