I recently installed python 3.7 on a Ubuntu 18.04.4 LTS machine using the following command:
sudo apt-get install python3.7
I also ran the following command since I want python 3.7 to be run as python3
:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
Subsequently I followed a suggestion to run this:
sudo apt autoremove
And now when I try to enable the universe
repository (add-apt-repository universe
), I get the following error:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, 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'
Most of the answers I find tell me to re-install python3-apt
like here and here, but that is not working.
What else can I try?
EDIT:
Here and here are also suggestions that involve specifically pointing to the dist installation of python, which is version 3.6 for Ubuntu 18.04. Is it safe to do this? Couldn't this python be upgraded at some point?
python3.7
or edit shebang of the source code (if using scripts). Changing Python versions can sometime break the OS. I'd recommend you to rollback the changes and makepython3
a symlink ofpython3.6
. – Kulfy Apr 21 '20 at 16:41