askubuntu.com 上没有针对 ModuleNotFoundError: No module named 'apt_pkg' in Ubuntu 16.04 的答案

askubuntu.com 上没有针对 ModuleNotFoundError: No module named 'apt_pkg' in Ubuntu 16.04 的答案

我运行了以下命令:

~$ sudo add-apt-repository "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-8.0"

sudo: unable to resolve host root
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 12, 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'

为了解决这个问题,我冒了无数次险,正如 askubuntu.com 所说

sudo apt-get install python-apt
sudo: unable to resolve host root
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-apt is already the newest version (1.1.0~beta1ubuntu0.16.04.9).
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 393 not upgraded.


~$ sudo apt-get install python3-apt --reinstall
sudo: unable to resolve host root
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 393 not upgraded.
Need to get 0 B/147 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 208998 files and directories currently installed.)
Preparing to unpack .../python3-apt_1.1.0~beta1ubuntu0.16.04.9_i386.deb ...
Unpacking python3-apt (1.1.0~beta1ubuntu0.16.04.9) over (1.1.0~beta1ubuntu0.16.04.9) ...
Setting up python3-apt (1.1.0~beta1ubuntu0.16.04.9) ...


$ sudo ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.so
ln: failed to create symbolic link 'apt_pkg.cpython-34m-x86_64-linux-gnu.so': File exists


$ sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
cp: cannot stat 'apt_pkg.cpython-36m-x86_64-linux-gnu.so': No such file or directory

$ sudo apt-get install --reinstall python3-apt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 393 not upgraded.
Need to get 0 B/147 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 208998 files and directories currently installed.)
Preparing to unpack .../python3-apt_1.1.0~beta1ubuntu0.16.04.9_i386.deb ...
Unpacking python3-apt (1.1.0~beta1ubuntu0.16.04.9) over (1.1.0~beta1ubuntu0.16.04.9) ...
Setting up python3-apt (1.1.0~beta1ubuntu0.16.04.9) ...

$ sudo update-alternatives  --set python3  /usr/bin/python3.7

我分别尝试了这些命令。但仍然得到:

$ sudo add-apt-repository "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-8.0"
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 12, 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'

坦白说,我对这个错误感到厌烦,我确信上述命令和 askubuntu.com 其他问题中给出的命令都不能满足我的需求。作为最后的希望,我发布了这个问题。请回答我。

我非常非常难过,AskUbuntu.com 无法解决我的问题

编辑:我的 dist-packages 中有以下内容:

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

当我使用此命令时:

$ sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
cp: cannot stat 'apt_pkg.cpython-35m-x86_64-linux-gnu.so': No such file or directory

答案1

尝试以下简单而古老的程序。

cd /usr/lib/python3/dist-packages

sudo cp --remove-destination apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so

欲了解更多详情,请点击以下链接。

https://itectec.com/ubuntu/ubuntu-modulenotfounderror-no-module-named-apt_pkg-error/

相关内容