ModuleNotFoundError:没有名为“apt_pkg”的模块

ModuleNotFoundError:没有名为“apt_pkg”的模块
$ etcdctl
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 28, in <module>
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'.

我试图看看 etcdctl 是否有效。我也尝试过这个:https://stackoverflow.com/questions/41986507/unable-to-set-default-python-version-to-python3-in-ubuntu#:~:text=Type%20alias%20python%3Dpython3%20on,your%20alias %20应该%20是%20永久

答案1

根据这些答案:

我尝试了以下方法,它似乎有效:

  1. 使用以下命令查找相关apt_pkg文件:
    ls /usr/lib/python3/dist-packages/*apt_pkg*
    
  2. 建立必要的符号链接。以我为例,它是:
    sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
    

相关内容