python-ModuleNotFoundError没有名为apt_pkg的模块

我正在尝试使用命令添加存储库

 sudo add-apt-repository ppa:gezakovacs/ppa

以下是完全错误-

    Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, 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 23, 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'

Original exception was:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

克服错误.

我已经安装了python2,Python3.5&在Xubuntu 16.04上安装了Python3.6.
它会引起任何问题吗???

最佳答案
在执行apt-get升级时,我遇到了类似的问题…问题是apt-get试图使用python2.7,但是符号链接指向python3.4:

debian:/usr/bin# cat /etc/debian_version
8.10
debian:/usr/bin# ll /usr/bin/python
lrwxrwxrwx 1 root root 18 Feb 26 17:02 /usr/bin/python -> /usr/bin/python3.4

通过创建新的符号链接对其进行了修复

debian:/usr/bin# rm /usr/bin/python
debian:/usr/bin# ln -s /usr/bin/python2.7 /usr/bin/python

转载注明原文:python-ModuleNotFoundError没有名为apt_pkg的模块 - 代码日志