Ubuntu 20.04重装Python3后出现ModuleNotFoundError问题求助
Hey Bilal, sorry to hear you're stuck with this frustrating error after reinstalling Python 3 on Ubuntu 20.04. Let's walk through some targeted fixes that should resolve the ModuleNotFoundError for softwareproperties.SoftwareProperties:
Check your system's default Python 3 symlink
Ubuntu 20.04 relies on Python 3.8 as its default system Python, and mismatched symlinks are a common culprit here. First, verify wherepython3points:ls -l /usr/bin/python3
If it doesn't link to/usr/bin/python3.8, fix it with these commands:sudo rm /usr/bin/python3sudo ln -s /usr/bin/python3.8 /usr/bin/python3Fully reinstall
software-properties-common
A simple reinstall might not clear corrupted files—try purging the package completely first:sudo apt purge --auto-remove software-properties-commonsudo apt updatesudo apt install software-properties-commonVerify Python can access the
softwarepropertiesmodule
The module lives in/usr/lib/python3/dist-packages, so check if this path is in Python's system path. Runpython3in your terminal and enter:import sys; print(sys.path)
If/usr/lib/python3/dist-packagesisn't listed, ensure the directory has correct permissions:sudo chmod -R 755 /usr/lib/python3/dist-packages
You can also try re-registering the module via pip (though it's typically managed by apt):sudo python3 -m pip install --upgrade pipsudo python3 -m pip install software-properties-commonFix the
add-apt-repositoryscript's shebang line
Sometimes the script points to the wrong Python version. Open it with a text editor:sudo nano /usr/bin/add-apt-repository
Check the first line—it should be either#!/usr/bin/python3or#!/usr/bin/python3.8. If it's incorrect, modify it, save withCtrl+O, then exit withCtrl+X.Reinstall core system Python packages
If none of the above works, restore the minimal system Python components:sudo apt install --reinstall python3-minimal python3.8-minimal
Give these steps a try one by one—most users fix this issue with the first two steps. Let me know if you run into any snags!
备注:内容来源于stack exchange,提问作者Bilal

