损坏的终端、终结器和 apt

损坏的终端、终结器和 apt

我有一个 Ubuntu 18.LTS 并意外触发

更新替代方案--config python3.6

这似乎已经破坏了我的系统,因为现在终端、终结器和 apt 似乎都不起作用

终结者

Traceback (most recent call last):
  File "/usr/bin/terminator", line 23, in <module>
    import psutil
ModuleNotFoundError: No module named 'psutil'

终端

Traceback (most recent call last):
  File "/usr/bin/gnome-terminal", line 9, in <module>
    from gi.repository import GLib, Gio
ModuleNotFoundError: No module named 'gi'

易于

例如尝试添加存储库(只是尝试安装 3.5,因为它似乎是所有该程序的默认使用)

 internetmosquito@internetmosquito-PE72-7RD  ~  sudo add-apt-repository ppa:deadsnakes/ppa
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 12, in <module>
    from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
ModuleNotFoundError: No module named 'softwareproperties'

现在,我必须说我已经使用 pyenv 安装了不同版本的 Python:

 ✘ internetmosquito@internetmosquito-PE72-7RD  ~  pyenv versions
  system
  2.7.13
* 3.8.3 (set by /home/internetmosquito/.pyenv/version)
  3.9-dev

其中大部分安装在 /home/internetmosquito/.pyenv/versions 中

 internetmosquito@internetmosquito-PE72-7RD  ~  ls -ltra /home/internetmosquito/.pyenv/versions
total 20
drwxr-xr-x  6 internetmosquito internetmosquito 4096 jun 13  2020 3.9-dev
drwxr-xr-x  6 internetmosquito internetmosquito 4096 jun 16  2020 3.8.3
drwxrwxr-x 13 internetmosquito internetmosquito 4096 sep 27 20:35 ..
drwxr-xr-x  6 internetmosquito internetmosquito 4096 feb  9 01:05 2.7.13
drwxr-xr-x  5 internetmosquito internetmosquito 4096 feb  9 02:12 .

现在,如果我检查 /usr/bin/python 我会看到以下内容

 internetmosquito@internetmosquito-PE72-7RD  ~  ls -ltra /usr/bin/python*
lrwxrwxrwx 1 root root      16 mar 13  2020 /usr/bin/python3-config -> python3.8-config
lrwxrwxrwx 1 root root       9 mar 13  2020 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root     388 mar 28  2020 /usr/bin/python3-pasteurize
-rwxr-xr-x 1 root root     384 mar 28  2020 /usr/bin/python3-futurize
-rwxr-xr-x 1 root root     152 abr  9  2020 /usr/bin/python3-pbr
lrwxrwxrwx 1 root root      33 jul 28  2020 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
-rwxr-xr-x 1 root root 5486352 jul 28  2020 /usr/bin/python3.8
-rwxr-xr-x 1 root root 3629032 ago  4  2020 /usr/bin/python2.7
lrwxrwxrwx 1 root root      25 feb  8 23:49 /usr/bin/python3 -> /etc/alternatives/python3
lrwxrwxrwx 1 root root      24 feb  9 00:50 /usr/bin/python -> /etc/alternatives/python

似乎我没有“我认为”终结者使用的Python 3.5......

 internetmosquito@internetmosquito-PE72-7RD  ~  cat /usr/bin/terminator 
#!/usr/bin/python3

我的 python3 解析实际上与我的 python 相同......

 internetmosquito@internetmosquito-PE72-7RD  ~  python
Python 3.8.3 (default, Jun 16 2020, 18:30:59) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
 internetmosquito@internetmosquito-PE72-7RD  ~  python3
Python 3.8.3 (default, Jun 16 2020, 18:30:59) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

如果我再次尝试更新替代方案,我会收到此消息...

 internetmosquito@internetmosquito-PE72-7RD  ~  sudo update-alternatives --config python3
There is only one alternative in link group python3 (providing /usr/bin/python3): /usr/local/bin/python3.7
Nothing to configure.

甚至不知道为什么它在那里提到 python3.7 ?我确实在 /usr/local/bin 中看到了几个 python

✘ internetmosquito@internetmosquito-PE72-7RD  ~  ls -ltra /usr/local/bin/python*
lrwxrwxrwx 1 root root       17 dic 24  2018 /usr/local/bin/python3.7-config -> python3.7m-config
-rwxr-xr-x 2 root root 14925232 dic 24  2018 /usr/local/bin/python3.7m
-rwxr-xr-x 2 root root 14925232 dic 24  2018 /usr/local/bin/python3.7
-rwxr-xr-x 1 root root     3097 dic 24  2018 /usr/local/bin/python3.7m-config
-rwxr-xr-x 2 root root 14642520 feb  9 00:46 /usr/local/bin/python3.5m
-rwxr-xr-x 2 root root 14642520 feb  9 00:46 /usr/local/bin/python3.5
-rwxr-xr-x 1 root root     3071 feb  9 00:46 /usr/local/bin/python3.5m-config
lrwxrwxrwx 1 root root       17 feb  9 00:46 /usr/local/bin/python3.5-config -> python3.5m-config
lrwxrwxrwx 1 root root        9 feb  9 00:46 /usr/local/bin/python3 -> python3.5
lrwxrwxrwx 1 root root       16 feb  9 00:46 /usr/local/bin/python3-config -> python3.5-config

最重要的是 lsb_release 也不起作用!

 internetmosquito@internetmosquito-PE72-7RD  ~  lsb_release -a                 
Traceback (most recent call last):
  File "/usr/bin/lsb_release", line 25, in <module>
    import lsb_release
ModuleNotFoundError: No module named 'lsb_release'

甚至不知道还有多少其他东西被破坏了……有什么关于恢复正常但不意味着必须重新安装 Ubuntu 的建议吗?

谢谢!

根据 @Stewart 的回复进行更新

我正在使用 Xterm 来获取我在此处发布的输出。顺便说一句,我是 18.04,而不是 20.04

那么回到你的建议

 internetmosquito@internetmosquito-PE72-7RD  ~  file $(which terminator) $(which xterm) $(which gnome-terminal)
/usr/bin/terminator:     symbolic link to ../share/terminator/terminator
/usr/bin/xterm:          ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=abd5692fa8891e01f24e8ae7f40f218662f098d9, for GNU/Linux 3.2.0, stripped
/usr/bin/gnome-terminal: Python script, ASCII text executable

看来我的 gnome 终端也是基于 Python 的?

internetmosquito@internetmosquito-PE72-7RD  ~  file $(which add-apt-repository) $(which apt) $(which apt-cache) $(which dpkg)
/usr/bin/add-apt-repository: Python script, ASCII text executable
/usr/bin/apt:                ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c460d1db846110f4ae24cb54b4cfee967d022c09, for GNU/Linux 3.2.0, stripped
/usr/bin/apt-cache:          ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=2e75b0850b2936259281b093ecf906bf70a1d7b8, for GNU/Linux 3.2.0, stripped
/usr/bin/dpkg:               ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=978cfb3eb2e5cee720ae1c551c12595f1aa211f5, for GNU/Linux 3.2.0, stripped

检查 apt 等:

internetmosquito@internetmosquito-PE72-7RD  ~  file $(which add-apt-repository) $(which apt) $(which apt-cache) $(which dpkg)
/usr/bin/add-apt-repository: Python script, ASCII text executable
/usr/bin/apt:                ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=c460d1db846110f4ae24cb54b4cfee967d022c09, for GNU/Linux 3.2.0, stripped
/usr/bin/apt-cache:          ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=2e75b0850b2936259281b093ecf906bf70a1d7b8, for GNU/Linux 3.2.0, stripped
/usr/bin/dpkg:               ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=978cfb3eb2e5cee720ae1c551c12595f1aa211f5, for GNU/Linux 3.2.0, stripped

现在当我尝试检查 Python 3 时

 internetmosquito@internetmosquito-PE72-7RD  ~  ls -go $(which python3)  
-rwxrwxr-x 1 424 jun 13  2020 /home/internetmosquito/.pyenv/shims/python3

所以它看起来像指向 pyenv 安装的一些 python

答案1

首先,我建议使用不依赖于 python 的终端。 gnome-terminal或者xterm会起作用:

$ file $(which terminator) $(which xterm) $(which gnome-terminal)
/usr/bin/terminator:     Python script, ASCII text executable
/usr/bin/xterm:          ELF 64-bit LSB pie executable, ...
/usr/bin/gnome-terminal: ELF 64-bit LSB pie executable, ...

虽然 、和add-apt-repository可能是一个 python 脚本,但不是并且应该仍然适合您:aptdpkg

$ file $(which add-apt-repository) $(which apt) $(which apt-cache) $(which dpkg)
/usr/bin/add-apt-repository: Python script, ASCII text executable
/usr/bin/apt:                ELF 64-bit LSB pie executable, x86-...
/usr/bin/apt-cache:          ELF 64-bit LSB pie executable, x86-...
/usr/bin/dpkg:               ELF 64-bit LSB pie executable, x86-

您可以使用apt它来重新安装/重新配置损坏的软件包,包括一些损坏的链接。我正在进行 Debian 测试,但 Debian 和 Ubuntu 的核心 python 软件包是由同一个人维护的,所以我怀疑它对你来说是相似的。我在这里寻找相关的包:

$ ls -go $(which python3) 
lrwxrwxrwx 1 9 Dec 23 07:05 /usr/bin/python3 -> python3.9

$ dpkg -S $(which python3) $(which python3.9)
python3-minimal: /usr/bin/python3
python3.9-minimal: /usr/bin/python3.9

$ apt-cache show python3 | grep Depends:
Depends: python3.9 (>= 3.9.1-1~), ...
Pre-Depends: python3-minimal (= 3.9.1-1)

$ apt-cache show python3.9 | grep Depends:
Depends: python3.9-minimal (= 3.9.1-4)...

现在我们知道哪些包处理此链接以及与其关联的二进制文件。就您而言,您使用的是 Ubuntu 20.04,因此您需要python3.8而不是python3.9.

我会尝试用以下方法修复它:

sudo apt reinstall python3 python3-minimal python3.8 python3.8-minimal

其特别之处在于,它重新调用/var/lib/dpkg/info/<package>.{pre,post}{inst,rm}负责执行任何字节编译和使用update-alternatives(在适当时)的脚本。

如果这不起作用,我会看看 的输出update-alternatives --config python3。在 Debian 测试中我得到:

$ update-alternatives --config python3
update-alternatives: error: no alternatives for python3

如果你得到同样的结果,这意味着替代品不再管理 python3。我不确定这是什么时候改变的,如果你没有明白这一点,这可能就是你的机器出现问题的原因。当旧的 python3 版本被删除时,prerm负责的update-alternatives --remove python3永远不会运行。尝试运行update-alternatives --config python3并检查有哪些选项可用。如果您有python3.8作为选项,并且它是最高优先级,则重新运行此选项sudo并选择auto

$ update-alternatives --config python3
There are 3 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                    Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.8      1111      auto mode
  1            /usr/bin/python3.5      1101      manual mode
  2            /usr/bin/python3.8      1111      manual mode
  3            /usr/bin/python3.7      1081      manual mode

但是,我怀疑python3.8它不在您的列表中,这就是您遇到问题的原因。即使有了 Debian buster(2018 年发布),我们也有 python3.7,所以 python3.5 已经相当老了。由于python3包现在自行管理链接,因此当您运行时,update-alternatives --config python3您可能会用过时的链接替换良好的链接。在这种情况下,我将手动删除 python3 替代方案:

sudo update-alternatives --remove-all python3

然后再次重新安装 python 软件包。

每当发布新版本时python3,都会花费一些时间对存档中的所有依赖包运行测试。如果包失败,则会提交错误报告,维护人员会尽其所能确保他们的包适用于最新版本的python3.您通常不需要安装多个点版本。 terminator应该可以很好地与最新的python3.我怀疑如果它转换失败并且从未与 Ubuntu 20.04 一起发布,它就会从存档中删除。例外情况是 PPA(或任何第 3 方存储库),它们超出了官方发行版的范围,并且其中可能包含任何内容,包括terminator仅适用于python3.5.

相关内容