我一直在尝试从 Ubuntu 20.04 升级到 22.04。我尝试通过运行以下命令来执行此操作:
sudo do-release-upgrade
我遇到了以下情况:
Traceback (most recent call last):
File "/usr/bin/do-release-upgrade", line 11, in <module>
from UpdateManager.Core.MetaRelease import MetaReleaseCore
File "/usr/lib/python3/dist-packages/UpdateManager/Core/MetaRelease.py", line 25, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
我已经删除并重新安装了 python3-apt这里,但这没有任何作用。即使删除,我也遇到了类似的错误:
Removing ubuntu-advantage-tools (27.14.4~20.04) ...
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "/usr/lib/python3/dist-packages/uaclient/apt.py", line 14, in <module>
import apt # type: ignore
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
dpkg: error processing package ubuntu-advantage-tools (--remove):
installed ubuntu-advantage-tools package pre-removal script subprocess returned
error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
ubuntu-advantage-tools
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
据我所知,这也可能是因为我的 Python 版本不对(3.8)。使用 update-alternatives,我安装了 3.6。但现在当我在终端中运行 python --version 时,我仍然看到 3.8。不幸的是,我记不清我做了什么。我可能将“python”设为别名,但我找不到在哪里。
~/.bashrc 中没有 Python 的别名
有人能帮我理清我弄乱的事情吗?我很乐意分享更多信息。如何升级,如何降级到 Python 3.6?
答案1
我昨天刚遇到这个问题和其他问题并且能够升级,以下是我所做的:
继续https://wiki.ubuntu-it.org/Repository/SourcesList并将源代码带到您的下一个版本,如果您不想冒着系统崩溃的风险,请不要尝试跳转到更高的版本。事情必须逐步完成。获得正确的源代码后,复制它们,然后在终端中:sudo nautilus
然后继续/etc/apt/sources.list
将此文件复制到您可以访问的某个目录,~/Downloads
然后使用 gedit 或您选择的编辑器对其进行编辑,然后粘贴您从我链接的上一个站点复制的内容。之后返回终端:
sudo apt update
sudo apt upgrade
sudo apt-get dist-upgrade
sudo systemctl reboot # or simply reboot from the GUI