更新管理器出现问题:Ubuntu 13.10 中没有名为“apt_pkg”的模块,在 /usr/local/lib 上安装了 Python 3.4

更新管理器出现问题:Ubuntu 13.10 中没有名为“apt_pkg”的模块,在 /usr/local/lib 上安装了 Python 3.4

我对 Ubuntu 还不熟悉,正在尝试在 Ubuntu 13.10 上运行更新管理器。我得到:

jacopo@jacopo-laptop:~$ update-manager 
Traceback (most recent call last):
  File "/usr/bin/update-manager", line 28, in <module>
    from gi.repository import Gtk
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 27, in <module> from ._gi import _API
ImportError: No module named 'gi._gi'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "/usr/bin/update-manager", line 28, in <module>
from gi.repository import Gtk
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 27, in <module>
from ._gi import _API
ImportError: No module named 'gi._gi'

据我所知,这个问题与我应该安装python3.4有关。我在中安装了它/usr/local/lib,但我总是得到同样的错误。这样我甚至无法升级到Ubuntu 14.04。

答案1

重新安装apt_pkg使用:

sudo apt-get install --reinstall python3-apt

该错误主要是因为apt_pkg.cpython-35m-x86_64-linux-gnu.so不存在该库/usr/lib/python3/dist-packages

删除并重新安装应该有帮助。

答案2

update-alternatives  --set python3  /usr/bin/python3.6

答案3

以下解决方案对我有用:

cd  /usr/lib/python3/dist-packages
ls -la /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

如果您收到一条错误消息,指出符号链接级别过多,如下所示:

cp: failed to access '/usr/lib/python3/dist-packages/apt_pkg.so': Too many levels of symbolic links

然后您只需取消链接 apt_pkg.so 文件即可。使用以下命令:

sudo unlink apt_pkg.so

然后使用命令

sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

希望这可以帮助!

答案4

对我来说,这个办法很管用:

sudo apt install --reinstall python3-apt

这个问题实际上与这个问题类似: apt-get 损坏:没有名为 debian.deb822 的模块

相关内容