我想在 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
.更多的网络研究让我在 "ModuleNotFoundError: No module named 'apt_pkg'" appears in various commands - Ask Ubuntu 找到了这组命令。 :
sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt
其他网络资源也说了同样的话,所以我这样做了,但是当我运行 sudo add-apt-repository ppa:deadsnakes/ppa
时仍然收到错误消息.然后我找到了How to Fix 'add-apt-repository command not found' on Ubuntu & Debian - phoenixNAP ,它建议了这组命令:
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。在我做任何事情之前,我想问一下解决
ModuleNotFoundError: No module named 'apt_pkg'
的最佳方法是什么?鉴于我见过的可能解决方案的数量,尝试安装 deadsnakes 存储库以安装 Python 3.10 时出现错误消息。非常感谢。
最佳答案
这对我有用:
sudo apt-get install python3-apt --reinstall
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
上面文件名中的 38 对您来说可能不同。
关于python - ModuleNotFoundError : No module named 'apt_pkg' installing deadsnakes repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69949591/