Score:1

ModuleNotFoundError: No module named 'apt_pkg' trying to install deadsnakes repository

cn flag

I want to install Python 3.10 on Ubuntu 18.04 (I'm currently on Python 3.8) from the deadsnakes repository with the following set of commands I found on the internet:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.10

But I got the error "sudo: add-apt-repository: command not found."

More net research led me to this set of commands at "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

Other web sources said the same thing, so I did that, but I still get the error message when I run sudo add-apt-repository ppa:deadsnakes/ppa.

Then I found https://phoenixnap.com/kb/add-apt-repository-command-not-found-ubuntu, which advised this set of commands:

sudo apt update
sudo apt install software-properties-common
sudo apt update

so I did that, but when I run sudo add-apt-repository ppa:deadsnakes/ppa I now get this error message:

~$ sudo add-apt-repository ppa:deadsnakes/ppa Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 12, in from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 28, in import apt_pkg ModuleNotFoundError: No module named 'apt_pkg'

I have found some web links that show a wide variety of solutions with earlier versions of Python. I'm currently on Python 3.8.

Before I do anything more I want to ask what is the best way to solve the ModuleNotFoundError: No module named 'apt_pkg' error message when trying to install the deadsnakes repository to install Python 3.10, given the number of possible solutions I have seen. Is there another way of installing 3.10 other than building from source?

Thanks very much.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.