从 18.10 升级到 19.04 时出现 Python 错误

Nic*_*Hsu 5 upgrade python 19.04

我将 Python 2.7.15+ 符号python链接到python3. 当我尝试将 Ubuntu 升级到 19.04 时

sudo do-release-upgrade
Run Code Online (Sandbox Code Playgroud)

它返回以下错误:

Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-k7w2kx7r/disco", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeMain.py", line 238, in main
    if app.run():
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 2085, in run
    return self.fullUpgrade()
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 1906, in fullUpgrade
    if not self.askLivepatch():
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 1175, in askLivepatch
    version = next((r.version for r in di.get_all("object") if r.series == self.toDist), self.toDist)
AttributeError: 'UbuntuDistroInfo' object has no attribute 'get_all'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/problem_report.py", line 497, in add_to_existing
    self.write(f)
  File "/usr/lib/python3/dist-packages/problem_report.py", line 450, in write
    block = f.read(1048576)
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

Original exception was:
Traceback (most recent call last):
  File "/tmp/ubuntu-release-upgrader-k7w2kx7r/disco", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeMain.py", line 238, in main
    if app.run():
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 2085, in run
    return self.fullUpgrade()
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 1906, in fullUpgrade
    if not self.askLivepatch():
  File "/usr/lib/python3/dist-packages/DistUpgrade/DistUpgradeController.py", line 1175, in askLivepatch
    version = next((r.version for r in di.get_all("object") if r.series == self.toDist), self.toDist)
AttributeError: 'UbuntuDistroInfo' object has no attribute 'get_all'
Run Code Online (Sandbox Code Playgroud)

在升级 Ubuntu 之前,我尝试升级所有 Python 包:

pip freeze --local | grep -v '^-e' | cut -d = -f 1  | xargs -n1 pip install -U
Run Code Online (Sandbox Code Playgroud)

这就是它失败的原因吗?

Nic*_*Hsu 6

我自己解决了这个问题。

我发现有问题的python脚本:

/usr/local/lib/python3.6/dist-packages/distro_info.py
Run Code Online (Sandbox Code Playgroud)

然后通过以下方式覆盖它:

https://salsa.debian.org/debian/distro-info/raw/master/python/distro_info.py
Run Code Online (Sandbox Code Playgroud)

然后运行 ​​sudo do-release-upgrade,成功。


小智 5

这似乎通常源于安装了 pip 的发行版信息版本掩盖了 apt 版本 [...]

如果您在这里寻找快速解决方案:

sudo python3 -m pip uninstall distro-info
sudo apt reinstall python3-distro-info
Run Code Online (Sandbox Code Playgroud)

https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1874250/comments/9

  • 遇到了从 20.04 升级到 20.10 的情况,可以确认这有效 (3认同)