Ubuntu

損壞的終端、終結器和 apt

  • February 9, 2021

我有一個 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 中看到了幾條蟒蛇

✘ 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

首先,我建議使用不依賴 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(或任何 3rd 方儲存庫),它們超出了官方發行版的範圍,並且可能包含任何內容,包括terminator僅適用於python3.5.

引用自:https://unix.stackexchange.com/questions/633539