简体   繁体   English

ModuleNotFoundError 没有名为 apt_pkg 的模块

[英]ModuleNotFoundError No module named apt_pkg

I am trying to add a repo using command我正在尝试使用命令添加一个 repo

 sudo add-apt-repository ppa:gezakovacs/ppa

Following is complete error -以下是完整的错误 -

    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'

getting above error.得到以上错误。

I have install python2 , Python3.5 & Python3.6 installed on Xubuntu 16.04.我已经在 Xubuntu 16.04 上安装了 python2 、 Python3.5 和 Python3.6 。 Does it causing any issue???它会导致任何问题吗???

This is likely because you switched python versions in a weird way.这可能是因为您以一种奇怪的方式切换了 python 版本。 Do you have /usr/lib/python3/dist-packages/apt_pkg.so ?你有/usr/lib/python3/dist-packages/apt_pkg.so吗? This can be missing if you removed a version of python.如果您删除了某个版本的 python,这可能会丢失。

The answer that worked for me was this from askubuntu forums :对我有用的答案是来自askubuntu 论坛

ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so

If you look at /usr/bin/add-apt-repository it says如果您查看/usr/bin/add-apt-repository它说

#!/usr/bin/python3

at the top.在顶部。 If you updated with a newer python (eg dist had 3.5 but you installed 3.7) your /usr/bin/python3 points to a python that does not have apt_pkg .如果您使用较新的 python 更新(例如 dist 有 3.5 但您安装了 3.7),您的/usr/bin/python3指向一个没有apt_pkg的 python。

You can temporarily edit /usr/bin/add-apt-repository to point to您可以临时编辑/usr/bin/add-apt-repository以指向

#!/usr/bin/python3.5

(insert your distro python version) (插入你的发行版 python 版本)

I had a similar problem, when doing apt-get upgrade... The problem is that apt-get was trying to use python2.7, but the symlink was pointing to python3.4:我有一个类似的问题,在做 apt-get upgrade 时......问题是 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

Fixed it by creating a new symlink通过创建新的符号链接修复它

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

为特定版本的 python 安装 python-dev 模块:

sudo apt install python3.6-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复'ModuleNotFoundError:没有名为'apt_pkg'的模块? - How to fix 'ModuleNotFoundError: No module named 'apt_pkg'? ModuleNotFoundError:没有名为“apt_pkg”的模块正在安装 deadsnakes 存储库 - ModuleNotFoundError: No module named 'apt_pkg' installing deadsnakes repository python add-apt-repository: ImportError: No module named 'apt_pkg' - python add-apt-repository: ImportError: No module named 'apt_pkg' Linux Mint 19上的Python3.7&#39;No module named apt_pkg&#39;错误 - Python3.7 'No module named apt_pkg' error on Linux Mint 19 python-dev安装错误:ImportError: No module named apt_pkg - python-dev installation error: ImportError: No module named apt_pkg ModuleNotFoundError: 没有名为“pkg”的模块 - ModuleNotFoundError: No module named 'pkg' python apt_pkg获取单个pkg详细信息? - python apt_pkg to obtain individual pkg details? ModuleNotFoundError:没有名为“my_pkg”的模块 - ModuleNotFoundError: No module named 'my_pkg' 使用apt_pkg以程序方式安装debian软件包时出错 - Error while installing debian packages programmitically using apt_pkg Pyinstaller 错误:ModuleNotFoundError:对于 Python 3.7 没有名为“pkg_resources.py2_warn”的模块 - Pyinstaller Error: ModuleNotFoundError: No module named 'pkg_resources.py2_warn' for Python 3.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM