Since you followed the instructions for installing Python 3.9.2, presumably, you also did
make install with
sudo. If you did that, then Python has been installed in
/usr/local/. The executable
python3 is placed in
/usr/local/bin/, which is earlier in your
PATH variable (i.e., the list of locations that are searched for when looking for programs). That is why when you type
python3, you get 3.9.2 .
You can confirm this by typing
env | grep PATH. One of the lines start with
PATH= and that's the list of locations that are searched when looking for programs. Paths earlier in the list have higher priority. Your list is probably like mine.
/usr/local/bin appears before
So, to fix your problem, just erase all traces of Python 3.9 . It is in
/usr/local/. Do this to remove them and yes, you will need to use
sudo rm -f -r /usr/local/lib/python3.9
sudo rm -f -r /usr/local/include/python3.9
sudo rm -f -r /usr/local/lib/libpython3.9.a
cd /usr/local/bin/. You'll have to delete all of the relevant files here. Unfortunately, they aren't contained in a directory that you can erase, so you will have to delete them one-by-one using
sudo. I believe these are the files you have to erase (I just installed Python 3.9.2 to replicate what you were seeing). Obviously, don't erase anything else:
2to3 idle3 pip3.9 python3 python3-config
2to3-3.9 idle3.9 pydoc3 python3.9
easy_install-3.9 pip3 pydoc3.9 python3.9-config
After you've done all this, in a new shell, you can type
which python3 and it should report
/usr/bin/python3. If you then type
ls -al /usr/bin/python3, you might see something like this:
lrwxrwxrwx 1 root root 9 Oct 6 18:28 /usr/bin/python3 -> python3.8*
This is a symbolic link (i.e., a "Windows shortcut) that points
By the way, answer at the link you showed is not relevant. That's for the case when someone has installed two versions of Python from the Ubuntu repositories. In your case, the second version was installed from the Python web site, outside of the Ubuntu repositories. So the answer at this link doesn't help you.
In summary, when you downloaded Python from Python's web site, compiled it and installed it, it is placed in
/usr/local/bin/. It isn't "registered" in any way with the Ubuntu system. All it did is put it in a location that is searched first before
/bin/. So, there's no single button that you can hit to remove all traces. You just have to go into
/usr/local/ and manually remove it. Since there will be other programs there, you can't remove all of it...you need to go in and remove a file or a directory at a time. Once you do that, then Python 3.8 will be found first.
I think this is correct now; I hope this helps.