Est*_*her 10 python apt dependencies
我们在这里收到了很多关于人们乱搞 Python 版本并破坏他们的系统的问题,最明显的是 apt 无法正常运行。我知道许多 Ubuntu 软件包需要特定版本的 Python才能正常运行。
我的问题是:是什么导致较新/不同的 Python 版本与 apt 不兼容?这些包是否依赖于仅存在于某些版本中的语言功能,或者 apt 依赖于哪些特定于版本的 Python 功能使其仅适用于某个特定的 Python 版本?
是的,通常是特定的语言特性只存在于某个Python版本中。
\n根据问题的不同,当 apt 或更可能是 dpkg 之类的应用程序调用使用新版本中不存在的错误语法的某些内容时,您通常会收到错误消息。
\n然而apt 本身并不依赖于 python,对于 dpkg \xe2\x80\x94 也是如此,但是依赖于 python 的包通常具有调用 python 或 python 脚本的安装前和安装后脚本。
\n例如,如果您下载 的 deb 文件software-properties-gtk
,解压该文件,然后解压该control.tar.xz
文件,您将看到一个prerm
脚本。
该脚本是一个 sh 脚本,但您可以看到它也调用 python:
\n#!/bin/sh\nset -e\n\n# Automatically added by dh_python3:\nif which py3clean >/dev/null 2>&1; then\n py3clean -p software-properties-gtk \nelse\n dpkg -L software-properties-gtk | perl -ne \'s,/([^/]*)\\.py$,/__pycache__/\\1.*, or next; unlink $_ or die $! foreach glob($_)\'\n find /usr/lib/python3/dist-packages/ -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir\nfi\n\n# End automatically added section\n
Run Code Online (Sandbox Code Playgroud)\nSopy3clean
是 的一部分python3-minimal
python3
,此脚本在文件第一行的 shebang 中调用,如以下命令所示:
which py3clean\n
Run Code Online (Sandbox Code Playgroud)\n这应该表明/usr/bin/py3clean
:
head /usr/bin/py3clean \n
Run Code Online (Sandbox Code Playgroud)\n输出:
\n#! /usr/bin/python3\n# vim: et ts=4 sw=4\n\n# Copyright \xc2\xa9 2010-2012 Piotr O\xc5\xbcarowski <piotr@debian.org>\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the "Software"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n
Run Code Online (Sandbox Code Playgroud)\n这很重要,因为正如您通过以下命令看到的那样,实际文件/usr/bin/python3
不存在:
file /usr/bin/python3\n
Run Code Online (Sandbox Code Playgroud)\n在 20.04 上,这告诉我这/usr/bin/python3
是一个到 python3.8 的符号链接,并which python3.8
显示该文件是/usr/bin/python3.8
. 此外,file /usr/bin/python3.8
确认这是用于 python3 的实际 Python 可执行文件。
因此software-properties-gtk
,如果安装了 python3,该包期望安装的 python3 版本是 python3.8。
该py3clean
脚本可能适用于不同的 Python 版本,也可能不适用于不同的 Python 版本,但通常会对 Python 进行足够多的更改,因此该脚本中的某个位置可能至少有一个更改会导致某种类型的错误。
即使不是针对这种特殊情况,您也明白了。
\n我想总结一下,这实际上不是 apt 的问题,而是更多的 python 问题,因为 python 脚本经常使用通用的 shebang,当 shebang 指定/usr/bin/python
or/usr/bin/python3
甚至/usr/bin/env python
or时,它需要特定版本的 python /usr/bin/env python3
,因为这些都没有指向一个实际的文件,它们都指向一个符号链接,该链接指向系统上安装的默认 python 版本。
由于大多数软件包都是针对特定版本的 Ubuntu 发布的,因此它们都期望 Python 的默认版本是相同的。否则,每个包都将依赖于任意不同的 Python 版本,并且我们最终可能会在同一系统上安装 3 个或更多版本的 Python,只是为了满足依赖关系。
\n通常,如果您想要或需要安装不同版本的 Python,那是因为您有特定的原因。出于这个原因,没有什么可以阻止您使用不同版本的 Python,只要您不弄乱其他软件在调用 或 时使用的默认 Pythonpython
版本python3
。
因此,如果您确实安装了备用版本,您将无法方便地通过python
或python3
作为默认版本 \xe2\x80\x94 调用该备用版本,您将需要通过调用 来专门指定版本python3.9
,例如,当您使用它时。
我想我应该为阅读此答案的其他人添加免责声明。如果你想在你的系统上安装不同版本的 python,你应该四处询问以找到正确的方法。一个系统上可以有多个版本的 Python,但为了避免出现问题,您不得以任何方式卸载、更改或更改 Python 的默认版本。但我认为更详细的内容不属于这个问题的范围。
\n 归档时间: |
|
查看次数: |
330 次 |
最近记录: |