dpkg错误:pycompile未找到

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

在尝试使用上述命令移除MySQL时,我遇到了以下错误:

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)

我该如何解决这个问题?


你能否接受下面的答案之一,@Kalyanam Rajashree? - John Greene
9个回答

60
啊,是的。Debian软件包管理中那个令人敬畏的“Catch-22”情况。问题在于Debian依赖于libpython3.x软件包中的py3compile作为一部分,而该软件包也提供了py3compile;这是行不通的。
我也曾因此受到影响,无法再次让py3compile正常工作,因为我已经删除了整个/usr/[/local]/lib/python3*目录。
一旦完成,Debian软件包管理工具将无法帮助您恢复到一个正常工作的Python3环境。您必须进行肉球手术。
在Debian中重建Python3需要三个关键步骤:
1. 恢复py3compile脚本(对于大多数人来说,您可能已经有了这个) 2. 恢复libpython3.7 3. 恢复python二进制文件
可以通过从另一个正常工作的Debian主机/系统重新复制/usr[/local]/lib目录来完成。但这次,我将详细介绍在有问题的主机内部的步骤(假设您没有另一个正常工作的主机)。
第一步 - 下载软件包

下载受影响的Debian软件包:

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

第二步 - 清理
清理旧的东西
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

第三步 - 从软件包中提取文件

让我们提取缺失的 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

第四步 - 恢复Python等
手动安装到根文件系统上。
cd /tmp/missing
ls -lR /tmp/missing  # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/*  /

第五步 - 验证
启动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.
>>>

测试导入并显示版本
>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
>>>
>>> quit()

第六步 - 整理自己
rm -rf /tmp/missing

第七步 - 通过Debian APT正式重新安装Python
dpkg -s -a  | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3

最有可能的是,你收到了许多处于“reinstreq”状态停滞中的包裹。
apt-get autoclean
apt-get autoremove
# (MANY PACKAGES FAILED TO BE INSTALLED)

此时,您将需要手动重新安装由apt-get autoremove列出的每一个软件...
apt-get install --fix-broken --reinstall <list-of-many-failed-packages>

最后一步 - 重新安装受影响的半状态Debian软件包

让我猜猜,你遇到了以下错误:

E: Internal Error, No file name for XXXXXX

我告诉你,你可能在你的/etc/apt/sources.list中有一个更新的Debian版本,它出了问题,把那个更新的版本从sources.list文件中移除(为了回到一个“稳定”的版本):对我来说这不是一个无法恢复的事情,只是你有点粗暴地搞乱了Debian软件包数据库。
最后一步的解决方案涉及通过重新安装几乎所有内容来恢复和稳定Debian软件包管理数据库。我稍后会详细说明,但要跟进的链接在这里here

5
我希望我能给这个点赞一千次,因为它让我免受更多的痛苦。 - Derrell Durrett
4
伙计,这救了我不用再花8小时来修复我的Python代码了。 - TheAshwaniK
4
好的,这个人刚刚让我从痛苦和永世罪恶中解脱出来。我完全同意 Derrell 的观点,我希望我能为此点赞一千次。我不明白为什么这不是被接受的答案?非常感谢 @JohnGreene!顺便提一下,在Ubuntu 16.04中,“dpkg -s -a | grep reinstreq”似乎没有起作用。我通过“dpkg -l | grep iFR”解决了这个问题。 - Javier Caselli
3
支持Python 3.9,因为这是我目前所使用的。;-) - John Greene
3
非常感谢,您的个人资料需要一个捐赠链接!这个答案提高了我的生活质量! - Captain Jack Sparrow
显示剩余7条评论

23

py3compile: 找不到命令

py3compile 命令是 python3-minimal 软件包的一部分,该软件包似乎已损坏。

要解决此问题,请尝试以下操作:

  • 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
    

然后,请确保py3compilepy3clean命令可以运行,并且可以从您的PATH变量访问。


1
在清理和清除所有内容之后,sudo apt install -f --reinstall python3-minimal 是关键。如上所述,如果您无法运行py3compile和py3clean,请不要尝试其他任何操作,直到修复为止。谢谢! - eramm
在我看来,这是最安全的解决方案。我的Ansible依赖项导致每次其他安装都会使dpkg失败,因为后安装脚本需要ppy3compile。sudo apt install -f --reinstall python3-minimal解决了问题,并使环境重新正常工作。感谢分享! - Maxime Flament

2
尽管py3compile和py3clean位于/usr/bin/中,但我的Lubuntu 16.10 shell (tcsh)一直在抱怨py3compile不存在。经过数小时的挣扎,我发现pycompile的第一行是:

! /usr/bin/env python

或类似的内容,它引用了我系统上的Python2.7。将其更改为指向Python 3:

! /usr/local/bin/python3

突然之间py3compile就出现了!

原来当py3compile引用Python2.7时,即使它在路径中或通过"/usr/bin/py3compile"直接执行,shell也会说py3compile不存在。shell甚至没有抱怨Python版本或任何东西,它只是声称py3compile本身不存在!

我陷入了这个混乱的境地,因为我想删除并重新安装Python 3.5,结果发现仍然存在Python 3,然后我发现它来自python-minimal,我尝试删除并重新安装python-minimal,但即使我尝试了网络上的所有方法和每个软件包管理器,它们都会抱怨py3compile缺失。现在我发现了这个修复py3compile的方法。


1
这对我很有帮助:
ln -s /usr/bin/python /usr/bin/python2

由于:
# head -1 `which pycompile`
#! /usr/bin/python2

0

我只用了以下代码就修复了错误:

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

检查 /usr/bin/pycompile 源代码,发现 bang 指向 python2 但不可用。


0

我陷入了这种情况,是因为我不小心忘记了update-alternatives的语法并运行了以下命令

# 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

之后,甚至python3命令也无法使用。

我不想重新安装整个Python3.6,因为我只是搞砸了二进制文件。所以我正在寻找一种获取二进制文件的方法,但无论我尝试使用aptapt-get或下载其他答案中提到的dpkg,我总是遇到pycompile无法工作的问题,因为它找不到Python3。

幸运的是,我注意到有一个/usr/bin/python3.6m,它与现有的Python版本大致相同,如python3.<x>和python3.<x>m之间的区别,所以我只需执行以下操作:

cp python3.6m python3.6

它有效了。我能再次使用python3命令

在此之后,dpkg仍将python3视为未配置,因此我不得不运行以下命令:

sudo apt-get install --reinstall python3

0
尝试这个:

首先删除不再需要的软件包:

sudo apt-get autoremove

清除已检索软件包文件的本地存储库
sudo apt-get autoclean

移除包(mysql-client未安装):

sudo apt-get remove mysql-server mysql-common

我尝试了所有提到的命令,但最终仍然出现相同的错误。 - Kalyanam Rajashree
我尝试了提到的所有命令,但最终仍然出现相同的错误。事实上,每当我尝试在我的Ubuntu上安装或卸载任何东西时(真的,什么都没有安装或卸载),我都会遇到同样的错误。 - Kalyanam Rajashree
这是一个更一般性的问题,我认为与dpkg有关。 - teoreda
关于 dpkg。是的,它是相关的。我能做什么? - Kalyanam Rajashree
现在,我卸载了Python(尽管遇到了很多错误)。现在,如果我尝试使用相同的命令卸载MySQL,我无法获取旧的deb文件列表,而是只能得到一个名称。它是libgksu2-0。 - Kalyanam Rajashree

0

尝试

apt install --reinstall hplip hplip-data

然后执行

apt install --reinstall python3


0
凭借一点运气和碰碰运气,我找到了一个更简单的方法。
sudo apt install --reinstall python3.11-minimal

或者根据需要更换您的Python版本。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接