14

Well. Yep. Wanted a fresh start because I was having dependency confusions, so I ran "whereis python" and literally erased all of the files and directories that came up. Then when I go to run apt-get install python I of course get lots of errors. Is there a way to reinstall python on ubuntu without just doing a clean wipe?

Here is the output of trying to install python binary:

root@ubuntu14-server:/home/kpoole# apt-get install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python is already the newest version.
The following packages were automatically installed and are no longer required:
libexpat1-dev libpython-dev libpython2.7-dev
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
15 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up python-chardet (2.0.1-2build2) ...
/var/lib/dpkg/info/python-chardet.postinst: 6: /var/lib/dpkg/info/python-chardet.postinst: pycompile: not found
dpkg: error processing package python-chardet (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-colorama (0.2.5-0.1ubuntu1) ...
/var/lib/dpkg/info/python-colorama.postinst: 6: /var/lib/dpkg/info/python-colorama.postinst: pycompile: not found
dpkg: error processing package python-colorama (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-distlib (0.1.8-1) ...
/var/lib/dpkg/info/python-distlib.postinst: 6: /var/lib/dpkg/info/python-distlib.postinst: pycompile: not found
dpkg: error processing package python-distlib (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-django (1.6.1-2ubuntu0.5) ...
/var/lib/dpkg/info/python-django.postinst: 6: /var/lib/dpkg/info/python-django.postinst: pycompile: not found
dpkg: error processing package python-django (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-django-tables2:
python-django-tables2 depends on python-django (>= 1.4.5); however:
Package python-django is not configured yet.

dpkg: error processing package python-django-tables2 (--configure):
dependency problems - leaving unconfigured
Setting up python-six (1.5.2-1) ...
No apport report written because MaxReports is reached already
                                              /var/lib/dpkg/info/python-six.postinst: 6: /var/lib/dpkg/info/python-six.postinst: pycompile: not found
dpkg: error processing package python-six (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-html5lib:
python-html5lib depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-html5lib (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              Setting up python-lxml (3.3.3-1ubuntu0.1) ...
/var/lib/dpkg/info/python-lxml.postinst: 6: /var/lib/dpkg/info/python-lxml.postinst: pycompile: not found
dpkg: error processing package python-lxml (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              Setting up python-minimal (2.7.5-5ubuntu3) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python-pkg-resources (3.3-1ubuntu1) ...
No apport report written because MaxReports is reached already
                                              /var/lib/dpkg/info/python-pkg-resources.postinst: 6: /var/lib/dpkg/info/python-pkg-resources.postinst: pycompile: not found
dpkg: error processing package python-pkg-resources (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-setuptools:
python-setuptools depends on python-pkg-resources (= 3.3-1ubuntu1); however:
Package python-pkg-resources is not configured yet.

dpkg: error processing package python-setuptools (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-urllib3:
python-urllib3 depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-urllib3 (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-requests:
python-requests depends on python-chardet; however:
Package python-chardet is not configured yet.
python-requests depends on python-urllib3 (>= 1.7.1); however:
Package python-urllib3 is not configured yet.

dpkg: error processing package python-requests (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-pip:
python-pip depends on python-colorama; however:
Package python-colorama is not configured yet.
python-pip depends on python-distlib; however:
Package python-distlib is not configured yet.
python-pip depends on python-html5lib; however:
Package python-html5lib is not configured yet.
python-pip depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-pip depends on python-setuptools (>= 0.6c1); however:
Package python-setuptools is not configured yet.
python-pip depends on python-six; however:
Package python-six is not configured yet.
python-pip depends on python-requests; however:
Package python-requests is not configured yet.

dpkg: error processing package python-pip (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              dpkg: dependency problems prevent configuration of python-virtualenv:
python-virtualenv depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-virtualenv depends on python-setuptools; however:
Package python-setuptools is not configured yet.

dpkg: error processing package python-virtualenv (--configure):
dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                              Errors were encountered while processing:
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
E: Sub-process /usr/bin/dpkg returned an error code (1)

After going the route suggested by ike:

root@ubuntu14-server:/home/kpoole# apt-get install --reinstall python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
python : Depends: python2.7 (>= 2.7.5-1~) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
root@ubuntu14-server:/home/kpoole# apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
libexpat1-dev libpython-dev libpython2.7-dev
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
python python2.7
Suggested packages:
python-doc python-tk python2.7-doc
The following NEW packages will be installed:
python python2.7
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
14 not fully installed or removed.
Need to get 0 B/330 kB of archives.
After this operation, 1,042 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package python2.7.
(Reading database ... 73738 files and directories currently installed.)
Preparing to unpack .../python2.7_2.7.6-8_amd64.deb ...
Unpacking python2.7 (2.7.6-8) ...
Selecting previously unselected package python.
Preparing to unpack .../python_2.7.5-5ubuntu3_amd64.deb ...
Unpacking python (2.7.5-5ubuntu3) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1) ...
Setting up python-minimal (2.7.5-5ubuntu3) ...
/var/lib/dpkg/info/python-minimal.postinst: 4: /var/lib/dpkg/info/python-minimal.postinst: python2.7: not found
dpkg: error processing package python-minimal (--configure):
subprocess installed post-installation script returned error exit status 127
Setting up python2.7 (2.7.6-8) ...
/var/lib/dpkg/info/python2.7.postinst: 9: /var/lib/dpkg/info/python2.7.postinst: python2.7: not found
dpkg: error processing package python2.7 (--configure):
subprocess installed post-installation script returned error exit status 127
dpkg: dependency problems prevent configuration of python:
python depends on python2.7 (>= 2.7.5-1~); however:
Package python2.7 is not configured yet.
python depends on python-minimal (= 2.7.5-5ubuntu3); however:
Package python-minimal is not configured yet.

dpkg: error processing package python (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-chardet:
python-chardet depends on python (>= 2.7); however:
Package python is not configured yet.
python-chardet depends on python (<< 2.8); however:
Package python is not configured yet.
python-chardet depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-chardet (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-colorama:
python-colorama depends on python (>= 2.7); however:
Package python is not configured yet.
python-coNo apport report written because the error message indicates its a followup error from a previous failure.
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
        No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
                    lorama depends on python (<< 2.8); however:
Package python is not configured yet.
python-colorama depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-colorama (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-distlib:
python-distlib depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-distlib depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.

dpkg: error processing package python-distlib (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-django:
python-django depends on python (>= 2.7); however:
Package python is not configured yet.
python-django depends on python (<< 2.8); however:
Package python is not configured yet.
python-django depends on python:any (>= 2.7.1-0ubuntu2); however:
Package pythNo apport report written because MaxReports is reached already
on is not configured yet.

dpkg: error processing package python-django (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-django-tables2:
python-django-tables2 depends on python (>= 2.7); however:
Package python is not configured yet.
python-django-tables2 depends on python (<< 2.8); however:
Package python is not configured yet.
python-django-tables2 depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.
python-django-tables2 depends on python-django (>= 1.4.5); however:
Package python-django is not configured yet.

dpkg: error processing package python-django-tables2 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-six:
python-six depends on python (>= 2.7); however:
Package python is not configured yet.
python-six depends on python (<< 2.8); however:
Package python is not configured yet.
python-six depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-six (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-html5lib:
python-html5lib depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-html5lib depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-html5lib depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-html5lib (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-lxml:
python-lxml depends on python (>= 2.7); however:
Package python is not configured yet.
python-lxml depends on python (<< 2.8); however:
Package python is not configured yet.
python-lxml depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.

dpkg: error processing package python-lxml (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-pkg-resources:
python-pkg-resources depends on python:any (>= 2.7); however:
Package python is not configured yet.
python-pkg-resources depends on python:any (<< 2.8); however:
Package python is not configured yet.

dpkg: error processing package python-pkg-resources (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-setuptools:
python-setuptools depends on python:any (>= 2.7); however:
Package python is not configured yet.
python-setuptools depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-setuptools depends on python-pkg-resources (= 3.3-1ubuntu1); however:
Package python-pkg-resources is not configured yet.

dpkg: error processing package python-setuptools (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-urllib3:
python-urllib3 depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-urllib3 depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-urllib3 depends on python-six; however:
Package python-six is not configured yet.

dpkg: error processing package python-urllib3 (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-requests:
python-requests depends on python:any (>= 2.7.5-5~); however:
Package python is not configured yet.
python-requests depends on python:any (<< 2.8); however:
Package python is not configured yet.
python-requests depends on python-chardet; however:
Package python-chardet is not configured yet.
python-requests depends on python-urllib3 (>= 1.7.1); however:
Package python-urllib3 is not configured yet.

dpkg: error processing package python-requests (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-pip:
python-pip depends on python (>= 2.7); however:
Package python is not configured yet.
python-pip depends on python (<< 2.8); however:
Package python is not configured yet.
python-pip depends on python:any (>= 2.7.1-0ubuntu2); however:
Package python is not configured yet.
python-pip depends on python-colorama; however:
Package python-colorama is not configured yet.
python-pip depends on python-distlib; however:
Package python-distlib is not configured yet.
python-pip depends on python-html5lib; however:
Package python-html5lib is not configured yet.
python-pip depends on python-pkg-resources; however:
Package python-pkg-resources is not configured yet.
python-pip depends on python-setuptools (>= 0.6c1); however:
Package python-setuptools is not configured yet.
python-pip depends on python-six; however:
Package python-six is not configured yet.
python-pip depends on python-requests; however:
Package python-requests is not c
dpkg: error processing package python-pip (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
python-minimal
python2.7
python
python-chardet
python-colorama
python-distlib
python-django
python-django-tables2
python-six
python-html5lib
python-lxml
python-pkg-resources
python-setuptools
python-urllib3
python-requests
python-pip
E: Sub-process /usr/bin/dpkg returned an error code (1)
1
  • python : Depends: python2.7 (>= 2.7.5-1~) but it is not going to be installed. I think your previous dependency conflicts are still troubling you. Can you also give output of dpkg -l | grep python Dec 26, 2014 at 19:35

5 Answers 5

23

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.

1
  • dpkg --check isn't a thing, a way to actually do this would be dpkg -l | grep -v '^ii' Apr 20, 2023 at 16:43
2

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.

13
  • I'm almost certain that all the python-* packages are included in the python meta-package. OP would not need to establish and maintain a list of packages to (un)/install. apt-get install --reinstall python should cover it.
    – amanthethy
    Dec 26, 2014 at 5:14
  • @amanthethy the "list" I mention is the hundreds of other packages that may also be uninstalled such as unity, all the scopes, accounts manager etc ... Also, I can name a few that are not included such as python pip for example.
    – mchid
    Dec 26, 2014 at 5:16
  • 1
    No, it won't hurt anyone - aside from the odd carpel tunnel - but it is unnecessary. Also, python-pip is a package manager for python programs. Its an application built using python and not a feature of the language itself.
    – amanthethy
    Dec 26, 2014 at 5:20
  • 1
    sudo apt-get install --reinstall ubuntu-desktop will cover all those extras you mentioned. [unity, scopes, python, accounts manager, etc.]
    – amanthethy
    Dec 26, 2014 at 5:22
  • 1
    No worries dude. Downvotes don't mean much to me as long as we are able to help the OP :)
    – amanthethy
    Dec 26, 2014 at 5:43
1

You should remove each package that gives you difficulties, then reinstall them.

See https://askubuntu.com/a/32899/176376 for removal without removing dependancies.

sudo dpkg -r --force-depends "package"

sudo apt-get install "package"

You should remove all of the problem ones first, and then install them again.

Run a sudo apt-get install -f and sudo dpkg --configure -a every few commands.

0
0

I see you have errors like this:

python2.7: not found

It means the python 2.7 executable cannot be found. I have used these command to find the package containing it (that would probably not work on your broken system, however)

$ which python2.7
/usr/bin/python2.7
$ dpkg -S /usr/bin/python2.7
python2.7-minimal: /usr/bin/python2.7

You need to reinstall it, but first you need to go through its dependencies. Use this commands to list them:

$ apt-cache depends python2.7-minimal
python2.7-minimal
  Depends: libpython2.7-minimal
  Depends: zlib1g
  PreDepends: libc6
  Suggests: binfmt-support
    binfmt-support:i386
  Recommends: python2.7
  Conflicts: binfmt-support
  Conflicts: binfmt-support:i386
  Replaces: python2.7
  Replaces: python2.7:i386
  Conflicts: python2.7-minimal:i386

libpython2.7-minimal is probably damaged. So I recommend you to first issue:

sudo apt-get install --reinstall libpython2.7-minimal

then:

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

and then hopefully your

sudo apt-get -f install

will succeed.

-1

That's expected behaviour. Deleting files is not the same as uninstalling a package or program.

You've deleted all the python related stuff from your install, but your package manager doesn't know this. When you go to install Python again, apt expects all those files to still be there and doesn't bother trying to re-download them. As far as apt is concerned, all of python is still installed; You never told it otherwise.

You can try the following to attempt to correct this:
sudo apt-get install --reinstall python

In the future, uninstall packages using apt-get remove or apt-get purge or graphically from the Ubuntu Software Centre.

3
  • 4
    A purge of python un-installs lots of dependencies, where the reinstall will not reinstall all those.
    – oldfred
    Dec 26, 2014 at 16:36
  • 1
    You are right just up to the second paragraph. Your method of "correct"ing the problem could just remove most of the packages of OP system.
    – Braiam
    Dec 26, 2014 at 19:06
  • @Braiam You're right. I took for granted that apt-get remove package can uninstall packages that apt-get install package won't necessarily restore. I've edited, but feel free to correct it if I'm still off.
    – amanthethy
    Dec 27, 2014 at 7:31

You must log in to answer this question.

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