ubuntu upgrade problem with py3compile not found

Ubuntu: 18.04

When I tried to do sudo apt-get upgrade it gives me this error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  libpython3.7-minimal libpython3.7-stdlib
Use 'sudo apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
1 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 python3-software-properties (0.96.24.32.7) ...
/var/lib/dpkg/info/python3-software-properties.postinst: 6: /var/lib/dpkg/info/python3-software-properties.postinst: py3compile: not found
dpkg: error processing package python3-software-properties (--configure):
 installed python3-software-properties package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 python3-software-properties
E: Sub-process /usr/bin/dpkg returned an error code (1)

But suggested commend sudo apt autoremove also shows error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED
  libpython3.7-minimal libpython3.7-stdlib
0 to upgrade, 0 to newly install, 2 to remove and 0 not to upgrade.
1 not fully installed or removed.
After this operation, 12.1 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 178285 files and directories currently installed.)
Removing libpython3.7-stdlib:amd64 (3.7.1-1~18.04) ...
Removing libpython3.7-minimal:amd64 (3.7.1-1~18.04) ...
Setting up python3-software-properties (0.96.24.32.7) ...
/var/lib/dpkg/info/python3-software-properties.postinst: 6: /var/lib/dpkg/info/python3-software-properties.postinst: py3compile: not found
dpkg: error processing package python3-software-properties (--configure):
 installed python3-software-properties package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 python3-software-properties
E: Sub-process /usr/bin/dpkg returned an error code (1)

So it looks like there is some problem with py3compile which is not found. I try sudo apt-get -f install which ends with:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up python3-software-properties (0.96.24.32.7) ...
/var/lib/dpkg/info/python3-software-properties.postinst: 6: /var/lib/dpkg/info/python3-software-properties.postinst: py3compile: not found
dpkg: error processing package python3-software-properties (--configure):
 installed python3-software-properties package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 python3-software-properties
E: Sub-process /usr/bin/dpkg returned an error code (1)

The same kind of py3compile: not found error shows when i try sudo apt-get install --reinstall python3-minimal

I'm new with ubuntu so I will be glad for some help with that.


dpkg error: pycompile: not found - Stack Overflow

This answer helped me, hope it resolves someones problem.

Reconfigure all unpacked, but unconfigured packages by:

sudo dpkg --configure -a

If above won't help, try reinstalling python3-minimal package by:

sudo apt install -f --reinstall python3-minimal

Alternatively run:

apt-get download python3-minimal
sudo dpkg -i *python3*.deb
sudo apt install -f

Or download the .pkg file from kernel.org and install from the file by:

sudo dpkg -i python3-minimal_*.deb

I got the problem of py3compile not found in Ubuntu 20.04.1 while installing python3-pip. I reinstalled python3-minimal as suggested by the answer and then again tried to installed python3-pip and it worked !

sudo apt install -f --reinstall python3-minimal

sudo apt install -f --reinstall python3-pip

Hope this helps someone in future !