dpkg error: pycompile: not found
Asked Answered
R

9

27
sudo apt-get remove --purge mysql-server mysql-client mysql-common

I am getting the following error as I try to remove mysql using the above command:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client' is not installed, so not removed
The following package was automatically installed and is no longer required:

  php5-mysqlnd

Use 'apt-get autoremove' to remove it.

The following extra packages will be installed:

  mysql-server-core-5.5 php5-mysqlnd python-aptdaemon

 python-aptdaemon.gtk3widgets python3-aptdaemon python3-aptdaemon.gtk3widgets

  python3-aptdaemon.pkcompat python3-uno python3-update-manager
  ubuntu-drivers-common update-manager

The following packages will be REMOVED:
  libdbd-mysql-perl* libmysqlclient18* mysql-client-5.5* mysql-common*
  mysql-server* mysql-server-5.5* php5-mysql* phpmyadmin*

The following NEW packages will be installed:
  php5-mysqlnd

The following packages will be upgraded:

  mysql-server-core-5.5 python-aptdaemon python-aptdaemon.gtk3widgets

  python3-aptdaemon python3-aptdaemon.gtk3widgets python3-aptdaemon.pkcompat

  python3-uno python3-update-manager ubuntu-drivers-common update-manager
10 upgraded, 1 newly installed, 8 to remove and 115 not upgraded.
170 not fully installed or removed.
Need to get 0 B/4,388 kB of archives.
After this operation, 89.9 MB disk space will be freed.
Do you want to continue? [Y/n] Y
Preconfiguring packages ...
(Reading database ... 354910 files and directories currently installed.)
Preparing to unpack .../ubuntu-drivers-common_1%3a0.2.91.9_amd64.deb ...
/var/lib/dpkg/info/ubuntu-drivers-common.prerm: 12: /var/lib/dpkg/info/ubuntu-drivers-common.prerm: py3clean: not found
dpkg: warning: subprocess old pre-removal script returned error exit status 127
dpkg: trying script from the new package instead ...
/var/lib/dpkg/tmp.ci/prerm: 12: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/ubuntu-drivers-common_1%3a0.2.91.9_amd64.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

/var/lib/dpkg/info/ubuntu-drivers-common.postinst: 6: 

/var/lib/dpkg/info/ubuntu-drivers-common.postinst: py3compile: not found
dpkg: error while cleaning up:

 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../python3-update-manager_1%3a0.196.13_all.deb ...

/var/lib/dpkg/info/python3-update-manager.prerm: 6: 

/var/lib/dpkg/info/python3-update-manager.prerm: py3clean: not found
dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/python3-update-manager_1%3a0.196.13_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

/var/lib/dpkg/info/python3-update-manager.postinst: 6: 

/var/lib/dpkg/info/python3-update-manager.postinst: py3compile: not found

dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../python3-aptdaemon.pkcompat_1.1.1-1ubuntu5.2_all.deb ...

/var/lib/dpkg/info/python3-aptdaemon.pkcompat.prerm: 6: 

/var/lib/dpkg/info/python3-aptdaemon.pkcompat.prerm: py3clean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/python3-aptdaemon.pkcompat_1.1.1-1ubuntu5.2_all.deb (--unpack):
 subprocess new pre-removal script returned error exit status 127

/var/lib/dpkg/info/python3-aptdaemon.pkcompat.postinst: 6: 

/var/lib/dpkg/info/python3-aptdaemon.pkcompat.postinst: py3compile: not found

dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../python3-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb ...

/var/lib/dpkg/info/python3-aptdaemon.gtk3widgets.prerm: 6: 

/var/lib/dpkg/info/python3-aptdaemon.gtk3widgets.prerm: py3clean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/python3-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/python3-aptdaemon.gtk3widgets.postinst: 6: 

/var/lib/dpkg/info/python3-aptdaemon.gtk3widgets.postinst: py3compile: not found

dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127
Preparing to unpack .../python3-aptdaemon_1.1.1-1ubuntu5.2_all.deb ...

/var/lib/dpkg/info/python3-aptdaemon.prerm: 6: /var/lib/dpkg/info/python3-aptdaemon.prerm: py3clean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/python3-aptdaemon_1.1.1-1ubuntu5.2_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/python3-aptdaemon.postinst: 6: 

/var/lib/dpkg/info/python3-aptdaemon.postinst: py3compile: not found

dpkg: error while cleaning up:

 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../update-manager_1%3a0.196.13_all.deb ...

/var/lib/dpkg/info/update-manager.prerm: 6: /var/lib/dpkg/info/update-manager.prerm: py3clean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/update-manager_1%3a0.196.13_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/update-manager.postinst: 6: /var/lib/dpkg/info/update-manager.postinst: py3compile: not found

dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../python-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb ...

/var/lib/dpkg/info/python-aptdaemon.gtk3widgets.prerm: 6: 

/var/lib/dpkg/info/python-aptdaemon.gtk3widgets.prerm: pyclean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: pyclean: not found

dpkg: error processing archive /var/cache/apt/archives/python-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127

No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/python-aptdaemon.gtk3widgets.postinst: 6: 

/var/lib/dpkg/info/python-aptdaemon.gtk3widgets.postinst: pycompile: not found

dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127
Preparing to unpack .../python-aptdaemon_1.1.1-1ubuntu5.2_all.deb ...

/var/lib/dpkg/info/python-aptdaemon.prerm: 6: /var/lib/dpkg/info/python-aptdaemon.prerm: pyclean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: pyclean: not found

dpkg: error processing archive /var/cache/apt/archives/python-aptdaemon_1.1.1-1ubuntu5.2_all.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127
No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/python-aptdaemon.postinst: 6: 

/var/lib/dpkg/info/python-aptdaemon.postinst: pycompile: not found

dpkg: error while cleaning up:

 subprocess installed post-installation script returned error exit status 127

Preparing to unpack .../python3-uno_1%3a4.2.8-0ubuntu2_amd64.deb ...

/var/lib/dpkg/info/python3-uno.prerm: 6: /var/lib/dpkg/info/python3-uno.prerm: py3clean: not found

dpkg: warning: subprocess old pre-removal script returned error exit status 127

dpkg: trying script from the new package instead ...

/var/lib/dpkg/tmp.ci/prerm: 6: /var/lib/dpkg/tmp.ci/prerm: py3clean: not found

dpkg: error processing archive /var/cache/apt/archives/python3-uno_1%3a4.2.8-0ubuntu2_amd64.deb (--unpack):

 subprocess new pre-removal script returned error exit status 127
No apport report written because MaxReports is reached already
                                                              /var/lib/dpkg/info/python3-uno.postinst: 6: /var/lib/dpkg/info/python3-uno.postinst: py3compile: not found

dpkg: error while cleaning up:

 subprocess installed post-installation script returned error exit status 127

Errors were encountered while processing:

 /var/cache/apt/archives/ubuntu-drivers-common_1%3a0.2.91.9_amd64.deb

 /var/cache/apt/archives/python3-update-manager_1%3a0.196.13_all.deb

 /var/cache/apt/archives/python3-aptdaemon.pkcompat_1.1.1-1ubuntu5.2_all.deb

 /var/cache/apt/archives/python3-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb

 /var/cache/apt/archives/python3-aptdaemon_1.1.1-1ubuntu5.2_all.deb

 /var/cache/apt/archives/update-manager_1%3a0.196.13_all.deb

 /var/cache/apt/archives/python-aptdaemon.gtk3widgets_1.1.1-1ubuntu5.2_all.deb

 /var/cache/apt/archives/python-aptdaemon_1.1.1-1ubuntu5.2_all.deb

 /var/cache/apt/archives/python3-uno_1%3a4.2.8-0ubuntu2_amd64.deb

E: Sub-process /usr/bin/dpkg returned an error code (1)

How do I resolve this ?

Rollway answered 21/6, 2015 at 7:56 Comment(1)
Can you accept an answer below from many answers, @Kalyanam Rajashree?Calorimeter
C
65

(EDIT: works in Python 3.11 down to 3.5)

Ahhhh, yes. The venerable "Catch-22" situation of Debian package management. It boils down to Debian depending on py3compile as part of the libpython3.x package when that package provides the py3compile as well; it's a no-go, there.

I too was bitten by this unable to get py3compile working again for I had too deleted the entire /usr/[/local]/lib/python3* directories.

Once done, nothing in Debian package management tool can help you get back to a working Python3 environment. You must do meat-ball surgery.

Reconstruction of Python3 in Debian entails three critical things:

  • Restoring py3compile script (for most of you, you already have this)
  • Restoring libpython3.7
  • Restoring python binary

One could do the RE-copying of /usr[/local]/lib directory from another working Debian host/system. But this time, I shall detail the steps from within the broken host in question (as if you do NOT have another working host).

Step 1 - Download Packages

Download the impacted Debian packages:

cd /tmp
apt-get download libpython3.7-minimal
apt-get download python3.7-minimal
apt-get download python3-minimal # (this is important)
apt-get download libpython3.7-stdlib
apt-get download python3.7

Step 2 - Cleanup

Clean up old stuff

rm -rf /usr[/local]/lib/python3.7*
rm -rf /usr[/local]/bin/python3.7*
update-alternatives --remove python3 /usr[/local]/bin/python3.7
hash -r  # removes cached python3 binary path

Step 3 - Extract files from packages

Let us extract the missing py3compile

cd /tmp
dpkg-deb -x python3-minimal_3.7.3-1_amd64.deb missing
dpkg-deb -x python3.7-minimal_3.7.3-2_amd64.deb missing
dpkg-deb -x libpython3.7-minimal_3.7.3-2_amd64.deb missing
dpkg-deb -x libpython3.7-stdlib_3.7.3-2_amd64.deb missing
dpkg-deb -x python3.7_3.7.3-2_amd64.deb missing

Step 4 - Restoring Python, et. al.

Manually install over your root filesystem

cd /tmp/missing
ls -lR /tmp/missing  # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/*  /

Step 5 - Verification

Start up Python3

python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Test import and show version

>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
>>>
>>> quit()

Step 6 - Clean up ourselves

rm -rf /tmp/missing

Step 7 - Officially reinstall Python via Debian APT

dpkg -s -a  | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3

Most likely, you got MANY packages that are in that stuck state of "reinstreq" state.

apt-get autoclean
apt-get autoremove
# (MANY PACKAGES FAILED TO BE INSTALLED)

At this point, you will have to manually reinstall each and every one of those listed by apt-get autoremove...

apt-get install --fix-broken --reinstall <list-of-many-failed-packages>

Last Step - Reinstalling impacted half-state Debian packages

Let me guess, you got the following error:

E: Internal Error, No file name for XXXXXX

I will tell you that you probably had a newer Debian release in your /etc/apt/sources.list for awhile, it went all down south (bad), and took that newer release out of the sources.list file (in effort to revert back to a 'stable' release): that's not an unrecoverable thing to me here, just that you jerked the Debian package database around a bit there ... rather brusquely.

The resolution of the last step entails a restoration and stabilization of the Debian package management database by reinstalling nearly everything. I will detail it later but the link to follow is given here.

Calorimeter answered 21/11, 2019 at 17:19 Comment(14)
I wish I could upvote this a thousand times, as it saved me no end of further pain....Strophic
@kenorb could always accept this answer. Still waiting.Calorimeter
Man.. this has saved from spending another 8 hrs fixing my pythons..Topless
Ok, this guy just freed me from a world of pain and eternal damnation. I totally concur with Derrell, I wish I could upvote this a thousand times. I wonder why this is not the accepted answer?? Thanks a ton @JohnGreene! Just a quick note, in Ubuntu 16.04 "dpkg -s -a | grep reinstreq" didn't seem to work. I worked around it with "dpkg -l | grep iFR".Titanic
Works with Python 3.9, because it’s what i do now. ;-)Calorimeter
Great sir, you need a donate link in your profile! This answer has improved my life quality!Reminiscence
Let me also express my grattitude for this solution, as well as add some keywords, as in my case the original issue was "Py_Initialize: Unable to get the locale encoding" and I encountered it on Raspbian.Crackerjack
I had to ensure all subversions of python3 were all the same (i.e. python3-minmal's deb package was 3.8.2-0ubuntu2, I had to install python3.8 packages) Thank you for the awesome answer!!!Stellite
Thank you so much for this amazing answer! I've spent about 3 hours trying to fix my system, trying suggestions from numerous other answers on Ubuntu SE, but nothing worked until this. And all because I accidentally overwrote /usr/bin/python3.11 with a symbolic link, and then the python3.11 package wouldn't reinstall because python3.11 was missing!Masterson
Can't believe this isn't the accepted answer!Cornea
I have tried to alert @kalyanam about this.Calorimeter
This SAVED me todayGarfish
Still saving people in 2024Incomparable
Ahahha @BestMamguEver I did the exact same today, made a simlink in the wrong direction... I had tried everything, and was about to reinstall ubuntu. He saved me :')Angulate
J
23

py3compile: not found

The py3compile command is part of python3-minimal package which seems to be broken.

To fix the issue, try the following:

  • Correct a system with broken dependencies in place by:

    sudo apt-get  -f install
    
  • 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
    

Then make sure that py3compile and py3clean commands are runnable and are accessible from your PATH variable.

Jokjakarta answered 1/11, 2017 at 15:7 Comment(2)
sudo apt install -f --reinstall python3-minimal is the key thing after all the purging and cleaning. As mentioned if you cant run py3compile and py3clean dont try anything else til that is fixed. Thanks !Palate
least dangerous solution in my opinion. my ansible dependency was making dpkg fail for each other installation because of the post installation, script that required ppy3compile. sudo apt install -f --reinstall python3-minimal did the trick and got the environment to work again. Thanks for sharing!Mellott
B
2

Despite py3compile and py3clean being present in /usr/bin/, my Lubunutu 16.10 shell (tcsh) kept complaining that py3compile was not there. After hours of frustration, I discovered that the first line in pycompile was:

! /usr/bin/env python

or something like that, which referred to Python2.7 on my system. Changing that to point to Python 3 with:

! /usr/local/bin/python3

suddenly made py3compile visible!

Turns out that the shell said py3compile did not exist even when it was in its path or was directly executed with "/usr/bin/py3compile" when py3compile referred to Python2.7. The shell did not even complain about the Python version or anything, it just claimed py3compile itself did not exist!

I got into this mess because I wanted to remove and reinstall Python 3.5, upon doing which I discovered that there is still a Python 3, which I then discovered comes from a python-minimal, which I tried to remove and reinstall. The python-minimal would not reinstall, even after I tried every thing I could find on the net and every package manager. They all would complain about py3compile missing. Now I discovered this fix for py3compile.

Bridgeboard answered 9/1, 2018 at 11:12 Comment(0)
T
1

This fixed it for me:

ln -s /usr/bin/python /usr/bin/python2

Because:

# head -1 `which pycompile`
#! /usr/bin/python2
Trip answered 20/11, 2021 at 0:44 Comment(0)
S
1

By shear luck and banging around, I found a simpler method

sudo apt install --reinstall python3.11-minimal

or replace your version of python as nessisary.

Sadness answered 27/6, 2023 at 20:17 Comment(0)
W
0

Try this:

First remove packages not more needed:

sudo apt-get autoremove

Clears out the local repository of retrieved package files

sudo apt-get autoclean

Remove the packages(mysql-client is not installed):

sudo apt-get remove mysql-server mysql-common
Walkout answered 21/6, 2015 at 8:12 Comment(5)
I tried all the commands mentioned. It still gives the same error at the end.Rollway
I tried all the commands mentioned. It still gives the same error at the end. In fact I am getting the same error whenever I try to install or remove anything(seriously, nothing is getting installed or removed) in my ubuntu.Rollway
It's a more general problem, I think is related to dpkg.Walkout
Related to dpkg. Yes it is. What can I do ?Rollway
Now, I uninstalled python(found many errors though). Now if I try uninstalling mysql using the same command, I am not getting the old list of deb files, instead I am getting only one name. It is libgksu2-0.Rollway
E
0

Try

apt install --reinstall hplip hplip-data

followed by

apt install --reinstall python3

Exscind answered 5/7, 2020 at 22:3 Comment(0)
L
0

I landed in this situation because I accidentally forgot the syntax of update-alternatives and ran the following command

# Don't do this!!!
sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python 20
# Should have been
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 20

After this even the python3 command was not working

I didn't want to go through re-installing the entire Python3.6 while I had only messed up the binary. So I was looking for a way to get the binary but whether I try apt or apt-get or download the dpkg as mentioned in other answers I always ended up with pycompile not working since it can't find Python3

Thankfully I noticed that there is a /usr/bin/python3.6m which is mostly the same as the existing Python version as per What's the difference between python3.<x> and python3.<x>m so I just did

cp python3.6m python3.6

And it worked. I was able to use the python3 command again

After this dpkg still considered python3 as unconfigured so I had to run

sudo apt-get install --reinstall python3
Lyonnais answered 5/11, 2021 at 16:37 Comment(0)
A
0

I fixed the error with just:

(cd /usr/bin ; ln -s python2.7 python2 -v)

Checking /usr/bin/pycompile source, found that the bang point to python2 and was not available.

Archerfish answered 17/8, 2022 at 11:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.