【发布时间】:2021-11-12 22:11:54
【问题描述】:
我想在 Ubuntu 18.04 上安装 Python 3.10(我目前使用的是 Python 3.8),使用我在 Internet 上找到的以下命令集从 deadsnakes 存储库:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10
但我收到错误“sudo: add-apt-repository: command not found.”
更多的网络研究使我在https://askubuntu.com/questions/1242009/modulenotfounderror-no-module-named-apt-pkg-appears-in-various-commands找到了这组命令:
sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt
其他网络资源也说了同样的话,所以我这样做了,但是当我运行 sudo add-apt-repository ppa:deadsnakes/ppa 时仍然收到错误消息。
然后我找到https://phoenixnap.com/kb/add-apt-repository-command-not-found-ubuntu,它建议了这组命令:
sudo apt update
sudo apt install software-properties-common
sudo apt update
所以我这样做了,但是当我运行 sudo add-apt-repository ppa:deadsnakes/ppa 时,我现在收到以下错误消息:
~$ sudo add-apt-repository ppa:deadsnakes/ppa
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 28, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
我发现了一些 Web 链接,其中显示了早期版本的 Python 的各种解决方案。我目前使用的是 Python 3.8。
在我做更多事情之前,我想问一下在尝试安装 deadsnakes 存储库以安装 Python 3.10 时解决 ModuleNotFoundError: No module named 'apt_pkg' 错误消息的最佳方法是什么,因为我有很多可能的解决方案见过。
非常感谢。
【问题讨论】:
-
也许你应该首先检查你是否有
add-apt-repository,最后使用/full/path/to/add-apt-repository。你可能对apt_pkg有问题,因为你运行remove python3-apt和后来的install python3-apt- 对我来说这是非常错误的想法。 -
我使用 Linux Mint 20(基于 Ubuntu 20.04),我无法使用 Ubunut 18.04 对其进行测试,但我有相同的命令,有两个名称
add-apt-repository和apt-add-repository- 也许你有 @ 987654334@ 而不是add-apt-repository -
我不确定,但较旧的 Ubuntu 可以使用
Python 3.6来运行系统功能 - 如果您甚至有Python 3.8,那么它仍然可能需要在Python 3.6中安装apt模块 -
顺便说一句:Python
3.10是一个非常新的版本,有些模块可能无法在这个版本上运行,所以最好等几个月再使用3.8 -
感谢您的 cmets。我会尝试你的前两个想法。如果我无法安装它,我可以从源代码构建,但如果可以的话,我想使用 deadsnakes。