Yesterday I have done several messes with my laptop, because I have uninstalled python3 on Ubuntu 20.04 because I have installed manually python 3.9 from the external repository https://www.python.org/downloads/release/python-392/.

I have lost ubuntu-desktop because I have learnt that the OS uses python 3.8 as default for many applications. Ok, I have reinstalled ubuntu-desktop and python 3.8 after many efforts and the PC is working fine. But how can I remove python 3.9? I have tried the classical commands like purge or remove but they do not work.

When I give python3.8 it gives me python 3.8 default version, but if I give python3 it open a shell in python 3.9.2.

I have also tried the selection suggested in the answer https://stackoverflow.com/questions/35047691/how-to-select-which-version-of-python-i-am-running-on-linux, but again it does not work. I just want to remove this python 3.9 package that I have installed from python.org.

When I run which python3.8 I obtain the path /usr/bin/python3.8, while the new python3 I have downloaded from the previous link to pyhon.org, go to download and downloaded the python 3.9.2, pushing the button. I have extracted the file and followed the README with the commands configure, make and make install.

  • Ubuntu 20? so this is Ubuntu Core 20? The problems you're describing however sound more like Ubuntu 20.04 LTS which is a different product to the yy based snap only releases such as Ubuntu Core 20. Please clarify your release, as Ubuntu has had yy and yy.mm format releases since 2016 and refer to different products. – guiverc Mar 26 at 10:13
  • It is Ubuntu 20 LTS Focal Fossa – TheOldJonny Mar 26 at 10:26
  • 1
    FYI Focal Fossa is "20.04" (released in April 2020)... – Ray Mar 26 at 10:27
  • We probably need a bit more information about where this other Python from python.org came from. You said the command is python3.8? Can you type which python3.8 and update your question to indicate where it actually is? I'm curious if you installed it as a normal user or as root. – Ray Mar 26 at 10:28
  • @Ray I have done the edit – TheOldJonny Mar 31 at 7:41

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 /usr/bin.

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:

  1. sudo rm -f -r /usr/local/lib/python3.9
  2. sudo rm -f -r /usr/local/include/python3.9
  3. sudo rm -f -r /usr/local/lib/libpython3.9.a

Lastly, 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 python3 to python3.8.

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.

  • I want to remove python3.9, in order to have a single python3 version on my laptop because I need many libraries for programming. When I type which python3 it returns /usr/local/bin/python3. When I type which python3.9 it returns me /usr/local/bin/python3.9 and when I type which python3.8 it returns /usr/bin/python3.8. I have done according your suggestion and when I give ls -al /usr/bin/python3 it returns lrwxrwxrwx 1 root root 9 mar 31 10:12 /usr/bin/python3 -> python3.8. But when I type in my terminal python3 it opens python3.9.2. – TheOldJonny Mar 31 at 8:19
  • @TheOldJonny So, I've edited my response according to the information you provided. I also installed Python 3.9.2 myself to see what you were seeing. Now I understand what's going on. I hope it's now correct -- let me know if you need further clarifications! – Ray Mar 31 at 15:30
  • thank you. I have removed in /usr/bin/local every python3.9 files. Now when I run python3, it gives me a shell of python3.8. – TheOldJonny Mar 31 at 16:57
  • @TheOldJonny You're welcome! I'm happy to hear that it was of help to you! I gave up installing from source a long time ago...unless I need a particular feature, I just wait until it's an official package so that upgrading it and erasing it is managed by Ubuntu... – Ray Apr 1 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.