Ubuntu 20.04突然开始报错:ModuleNotFoundError: No module named ‘apt_pkg’。
完整的报错信息是:
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'
看来跟Python有关,不知道是不是因为我把Python版本升级到3.10造成的。
解决方法如下,在终端中输入:
sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt
好了,问题解决了!