-4

I accidentally removed python from /usr/bin as it was conflicting with /usr/local/bin. (rm -rf /usr/bin/python*)

After realising my mistake i reinstall python3.8 and python2.7 from source. Python is now working.

I took some of the help from here.

OS: Ubuntu 20.04, with KDE, ZSH

But whenever i try to install any other package via apt this happens:

Setting up mercurial-common (5.3.1-1ubuntu1) ...
/var/lib/dpkg/info/mercurial-common.postinst: 8: pycompile: not found
dpkg: error processing package mercurial-common (--configure):
 installed mercurial-common package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 mercurial-common
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried sudo dpkg --configure -a which resulted in:

Setting up mercurial-common (5.3.1-1ubuntu1) ...
/var/lib/dpkg/info/mercurial-common.postinst: 8: pycompile: not found
dpkg: error processing package mercurial-common (--configure):
 installed mercurial-common package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 mercurial-common

I tried sudo apt-get install mercurial-common mercurial which resulted in:


Reading package lists... Done
Building dependency tree       
Reading state information... Done
mercurial-common is already the newest version (5.3.1-1ubuntu1).
Suggested packages:
  kdiff3 | kdiff3-qt | kompare | meld | tkcvs | mgdiff qct
The following NEW packages will be installed:
  mercurial
0 upgraded, 1 newly installed, 0 to remove and 32 not upgraded.
1 not fully installed or removed.
Need to get 0 B/323 kB of archives.
After this operation, 1,092 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 564968 files and directories currently installed.)
Preparing to unpack .../mercurial_5.3.1-1ubuntu1_amd64.deb ...
Unpacking mercurial (5.3.1-1ubuntu1) ...
Setting up mercurial-common (5.3.1-1ubuntu1) ...
/var/lib/dpkg/info/mercurial-common.postinst: 8: pycompile: not found
dpkg: error processing package mercurial-common (--configure):
 installed mercurial-common package post-installation script subprocess returned error exit status 127
dpkg: dependency problems prevent configuration of mercurial:
 mercurial depends on mercurial-common (= 5.3.1-1ubuntu1); however:
  Package mercurial-common is not configured yet.

dpkg: error processing package mercurial (--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: mercurial-common mercurial E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried sudo apt-get install --fix-broken:

Package mercurial-common is not configured yet.

dpkg: error processing package mercurial (--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: mercurial-common mercurial E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried to install mercurial from source by sudo make install (as on the page) the end was:

running install_scripts
copying build/scripts-3.8/hg -> /usr/local/bin
changing mode of /usr/local/bin/hg to 775
running install_egg_info
Removing /usr/local/lib/python3.8/site-packages/mercurial-5.9.3-py3.8.egg-info
Writing /usr/local/lib/python3.8/site-packages/mercurial-5.9.3-py3.8.egg-info
make -C doc
make[1]: Entering directory '/home/black/Downloads/mercurial-debian-master/doc'
python3 runrst hgmanpage  --halt warning \
  --strip-elements-with-class htmlonly hgrc.5.txt hgrc.5
abort: couldn't generate documentation: docutils module is missing
please install python-docutils or see http://docutils.sourceforge.net/
make[1]: *** [Makefile:33: hgrc.5] Error 255
make[1]: Leaving directory '/home/black/Downloads/mercurial-debian-master/doc'
make: *** [Makefile:81: doc] Error 2
╭─   ~/Downloads/mercurial-debian-mast

I am not able to install any package from apt because of this and i am not able to configure mercurial.

I tried downloading mercurial-common's .deb and installing it as it was on ubuntu:

$ apt-get download mercurial-common
$ sudo dpkg -i mercurial-common_5.3.1-1ubuntu1_all.deb
(Reading database ... 564985 files and directories currently installed.)
Preparing to unpack mercurial-common_5.3.1-1ubuntu1_all.deb ...
/var/lib/dpkg/info/mercurial-common.prerm: 12: pyclean: not found
dpkg: warning: old mercurial-common package pre-removal script subprocess returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 12: pyclean: not found
dpkg: error processing archive mercurial-common_5.3.1-1ubuntu1_all.deb (--install):
 new mercurial-common package pre-removal script subprocess returned error exit status 127
/var/lib/dpkg/info/mercurial-common.postinst: 8: pycompile: not found
dpkg: error while cleaning up:
 installed mercurial-common package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 mercurial-common_5.3.1-1ubuntu1_all.deb

As asked i tried:

cd /var/cache/apt/archives/ && sudo rm -rf *.deb
sudo apt --purge autoremove mercurial\*

(I am using zsh, so mercurial* wont work), resulted in:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'mercurial-keyring' for glob 'mercurial*'
Note, selecting 'mercurial-git' for glob 'mercurial*'
Note, selecting 'mercurial-buildpackage' for glob 'mercurial*'
Note, selecting 'mercurial-common' for glob 'mercurial*'
Note, selecting 'mercurial' for glob 'mercurial*'
Note, selecting 'mercurial-crecord' for glob 'mercurial*'
Note, selecting 'mercurial-extension-utils' for glob 'mercurial*'
Package 'mercurial-git' is not installed, so not removed
Package 'mercurial-buildpackage' is not installed, so not removed
Package 'mercurial-crecord' is not installed, so not removed
Package 'mercurial-extension-utils' is not installed, so not removed
Package 'mercurial-keyring' is not installed, so not removed
The following packages will be REMOVED:
  mercurial* mercurial-common*
0 upgraded, 0 newly installed, 2 to remove and 32 not upgraded.
2 not fully installed or removed.
After this operation, 15.1 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 564985 files and directories currently installed.)
Removing mercurial (5.3.1-1ubuntu1) ...
dpkg: error processing package mercurial-common (--remove):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
dpkg: too many errors, stopping
Errors were encountered while processing:
 mercurial-common
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

Also tried reinstalling:

$ sudo apt-get install --reinstall mercurial mercurial-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  kdiff3 | kdiff3-qt | kompare | meld | tkcvs | mgdiff qct
The following NEW packages will be installed:
  mercurial
0 upgraded, 1 newly installed, 1 reinstalled, 0 to remove and 32 not upgraded.
1 not fully installed or removed.
Need to get 2,973 kB of archives.
After this operation, 1,092 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 mercurial-common all 5.3.1-1ubuntu1 [2,650 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 mercurial amd64 5.3.1-1ubuntu1 [323 kB]
Fetched 2,973 kB in 5s (635 kB/s)   
(Reading database ... 564968 files and directories currently installed.)
Preparing to unpack .../mercurial-common_5.3.1-1ubuntu1_all.deb ...
/var/lib/dpkg/info/mercurial-common.prerm: 12: pyclean: not found
dpkg: warning: old mercurial-common package pre-removal script subprocess returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 12: pyclean: not found
dpkg: error processing archive /var/cache/apt/archives/mercurial-common_5.3.1-1ubuntu1_all.deb (--unpack):
 new mercurial-common package pre-removal script subprocess returned error exit status 127
/var/lib/dpkg/info/mercurial-common.postinst: 8: pycompile: not found
dpkg: error while cleaning up:
 installed mercurial-common package post-installation script subprocess returned error exit status 127
Preparing to unpack .../mercurial_5.3.1-1ubuntu1_amd64.deb ...
Unpacking mercurial (5.3.1-1ubuntu1) ...
Errors were encountered while processing:
 /var/cache/apt/archives/mercurial-common_5.3.1-1ubuntu1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Also for references: (Mercurial is depends on python2 and i have it installed.

$ which pycompile
/usr/bin/pycompile
$ which pyclean
/usr/bin/pyclean
$ which python2.7
/usr/local/bin/python2.7
$ ls -la /usr/local/bin/python*
-rwxr-xr-x 1 root root  5490488 Nov  8 00:17 /usr/local/bin/python
lrwxrwxrwx 1 root root        9 Nov  8 03:21 /usr/local/bin/python2 -> python2.7
-rwxr-xr-x 1 root root  9795824 Nov  8 03:19 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root     1687 Nov  8 03:19 /usr/local/bin/python2.7-config
lrwxrwxrwx 1 root root       16 Nov  8 03:21 /usr/local/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root        9 Nov  8 15:36 /usr/local/bin/python3 -> python3.7
-rwxr-xr-x 2 root root 17917584 Nov  8 15:35 /usr/local/bin/python3.7
lrwxrwxrwx 1 root root       17 Nov  8 15:36 /usr/local/bin/python3.7-config -> python3.7m-config
-rwxr-xr-x 2 root root 17917584 Nov  8 15:35 /usr/local/bin/python3.7m
-rwxr-xr-x 1 root root     2902 Nov  8 15:36 /usr/local/bin/python3.7m-config
-rwxr-xr-x 1 root root 20551712 Nov  8 02:33 /usr/local/bin/python3.8
-rwxr-xr-x 1 root root     3087 Nov  8 02:33 /usr/local/bin/python3.8-config
lrwxrwxrwx 1 root root       16 Nov  8 15:36 /usr/local/bin/python3-config -> python3.7-config

Black Chase
  • 445
  • 1
  • 5
  • 16
  • You haven't provided any OS & release details; but did you put the correct version of Ubuntu for your unstated release; and problems can occur if the default python isn't the correct version. You mention install from source? which I don't understand, even if apt & package front-ends (like apt) no longer work; dpkg would have let you install the correct deb package – guiverc Nov 08 '21 at 08:27
  • 1
    OS is Ubuntu 20.04 with KDE. What kind of release details are you asking? @guiverc Also i could not find .deb for mercurial. – Black Chase Nov 08 '21 at 08:34
  • cd /var/cache/apt/archives/ && sudo rm -rf *.deb run this command and report back – Error404 Nov 08 '21 at 08:41
  • Also run sudo apt --purge autoremove mercurial* – Error404 Nov 08 '21 at 08:42
  • @Algnis tried and updated the question. – Black Chase Nov 08 '21 at 08:49
  • 1
    Please do not change the default version of Python. You can install additional versions from the Deadsnakes PPA, but do not replace the default python with something else. Now apt is all messed up, and the easiest way to fix would be to reinstall. – Archisman Panigrahi Nov 08 '21 at 09:35
  • 1
    as sugested above comment, you purge the mercurial package. and then try to 'sudo apt -f install'. additionaly , don't expect mercurial to work in python3, it's required python2. So add the python2 to PYTHONPATH. and then you need to reinstall python-support package as depends on mercurial. finally try again reinstall the mercurial and mercurial-common packages. Let me what the result. – abu-ahmed al-khatiri Nov 08 '21 at 09:50
  • As shown i am not able to purge/remove mercurial. Took @ArchismanPanigrahi 's advice and installed python3.7 and set as default (as required by ubuntu 20.04).

    Added python2.7 to path for good measure and provided default output for various python versions order. Not sure what other support packages are needed as reinstalling didn't work. Refer last appends.

    – Black Chase Nov 08 '21 at 10:20
  • 1
    First of all try installing dependencies pyclean and pycompile by pip or apt then if the error is still there report back and maybe try this command toosudo rm -rf /var/lib/dpkg/info/mercurial* – Error404 Nov 08 '21 at 10:27
  • Also after running the commands I suggested you will get another error but more or less it wouldn't effect anything and you would be able to run all apt commands again (only 1 line of error would be there) – Error404 Nov 08 '21 at 10:32
  • I was able to install pyclean, but for pycompile : ERROR: Could not find a version that satisfies the requirement pycompile (from versions: none). After rm -rf, i tried purge removing mercurial, but this again:
     package is in a very bad inconsistent state; you should
     reinstall it before attempting a removal
    dpkg: too many errors, stopping
    Errors were encountered while processing:
     mercurial-common
    Processing was halted because there were too many errors.```
    
    – Black Chase Nov 08 '21 at 10:38
  • 1
    I suggested reinstalling Ubuntu from scratch, not reinstalling Python. – Archisman Panigrahi Nov 08 '21 at 10:42
  • xD wont be needed any more, I found a fix. – Black Chase Nov 08 '21 at 10:54

1 Answers1

-3

After installing python2.7 , python3.7 from scratch. I installed pyclean with pip2. I had to install pip2 aswell so i did this:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2 get-pip.py

Then removed mercurial dpkg's by:

sudo rm -rf /var/lib/dpkg/info/mercurial*

Then i tried reinstalling mercurial:

sudo apt install --reinstall  mercurial mercurial-common

But that did not work until i did this:

sudo apt-get -m --reinstall install python2.7 python2.7-minimal dh-python python3 python3-minimal 
sudo update-alternatives --install /usr/local/bin/python python /usr/local/bin/python3 12
sudo update-alternatives --install /usr/local/bin/python python /usr/local/bin/python2 11
sudo dpkg --configure -a 

And now apt update/install/upgrade is working fine. Thanks to all the comments.

Black Chase
  • 445
  • 1
  • 5
  • 16
  • 1
    Good to know , I get the credit for the main command that is sudo rm -rf /var/lib/dpkg/info/mercurial* – Error404 Nov 08 '21 at 10:55