Score:18

Which Python versions can be safely removed from Ubuntu 20.04?

us flag

I have the following versions of Python on my laptop running Ubuntu 20.04:

python2
python3.10
python3.9
python3-pasteurize
python2.7
python3.8
python3-config
python-argcomplete-check-easy-install-script
python3
python3.8-config
python3-futurize
python-argcomplete-tcsh

I know that Ubuntu relies on some of those, which ones can I safely remove?


EDIT: As asked in the comments, here is the output of ls -l /usr/bin/python[23]* /usr/local/bin/python[23]* :

ls: cannot access '/usr/local/bin/python[23]*': No such file or directory
lrwxrwxrwx 1 root root       9 Mar 13  2020  /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3674216 Mar  8  2021  /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Mar 12  2021  /usr/bin/python3 -> python3.8
-rwxr-xr-x 1 root root 5454136 Oct  5 00:09  /usr/bin/python3.10
-rwxr-xr-x 1 root root 5490488 Sep 28 18:10  /usr/bin/python3.8
lrwxrwxrwx 1 root root      33 Sep 28 18:10  /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config
-rwxr-xr-x 1 root root 5405872 Sep 10 01:20  /usr/bin/python3.9
lrwxrwxrwx 1 root root      16 Mar 13  2020  /usr/bin/python3-config -> python3.8-config
-rwxr-xr-x 1 root root     384 Mar 28  2020  /usr/bin/python3-futurize
-rwxr-xr-x 1 root root     388 Mar 28  2020  /usr/bin/python3-pasteurize
cn flag
I can guarantee you will need the 2 connected to python2 and python3 (those are symlinks). All others are up for you to decide. "safe" is relative... it will remove all connected apps if you delete 3.10. Not a problem to me but you might disagree ;-)
us flag
So python3.8 and python3.9 can be removed without breaking my Ubuntu install, right ?
us flag
Thank you, I edited my post. Hope it is better now
muru avatar
us flag
Yes, that's much better. Also add the output of `ls -l /usr/bin/python[23]* /usr/local/bin/python[23]*`, please.
us flag
Ok, please see my edit
us flag
The default python version in Ubuntu 20.04 is 3.8, do not remove that. How did you install so many versions of python?
cn flag
@JorisLimonier no. see the symlinks. 2.7 and 3.8 are needed by the system itself.
Artur Meinild avatar
vn flag
@Rinzwind the system does not depend on python2, it was installed by the OP (directly or as a dependency). ;-)
Mark avatar
ke flag
You've actually only got four versions of Python: 2.7, 3.8, 3.9, and 3.10. Everything else is either not Python, or is a synonym for one of those four.
us flag
@ArturMeinild, how did you deduce that?
Artur Meinild avatar
vn flag
@JorisLimonier Python2 is not installed on 20.04 by default, therefore it should be safe to remove since it's installed by the user.
Score:15
cn flag

These 2 are important:

lrwxrwxrwx 1 root root       9 Mar 13  2020  /usr/bin/python2 -> python2.7
lrwxrwxrwx 1 root root       9 Mar 12  2021  /usr/bin/python3 -> python3.8

Anything started with python2 expects python 2.7 to be there. And the same goes for python3: it expects python3.8. To be on the safe side: keep python2.7 too; it might not be needed but removing it can break the system.

All others are manually added versions. Removing those will keep the system working but it will delete all software relates to it. So do inspect the packages when you do apt purge or apt remove. If you plan to delete 2.7 too do take extra attention on what the system will delete along with it.

Artur Meinild avatar
vn flag
I once installed Midnight Commander on my 20.04, and it installed Python 2.7 as a dependency. However, both MC and Python 2 could be removed again without any issue,
cn flag
Hmmm that would do it indeed. Just a matter of looking at the suggestions it shows when purging/removing. Most ppl just type Y without looking (as do I :-) )
wjandrea avatar
cn flag
It'd help to clarify that `/usr/bin/python2.7` and `/usr/bin/python3.8` are the targets of these symlinks. Newbies might not realize that `-> python2.7` means a relative symlink.
Score:14
vn flag

The default Python version in Ubuntu 20.04 is Python 3.8. All other versions are something you installed yourself (or a dependency of something you installed).

So the system will only depend on 3.8, but other applications or projects you have may depend on the other versions (including Python 2/2.7).

Score:14
cn flag

You can also run apt rdepends --installed python3.9 to find out what packages depend on python3.9.

Example output of apt rdepends --installed python3.8 as this is the version installed on my machine:

python3.8
Reverse Depends:
  python3.8-minimal
  python3.8-minimal
  python3-uno
  rhythmbox-plugins
  python3.8-minimal
  python3
  python3-uno
  xviewer-plugins
wjandrea avatar
cn flag
To be clear, `python3` is the important one there. If you run `apt rdepends --installed python3`, you'll see a huge list, for example `gnome-shell` and `ubuntu-minimal`.
Dion avatar
cn flag
@wjandrea Isn't `python3` just a symbolic link that points to a specific version, e.g. `python3 -> python3.8` in OP's `ls -l`? So theoretically you can make it point to any `python3.x` version you would like. I say theoretically because I don't know what are the breaking changes in 3.8 vs 3.9 vs 3.10, but I suppose there are some.
wjandrea avatar
cn flag
If you change the symlink, things will break, like [Gnome Terminal for example](/q/880188/301745). IIRC, this is because the system libraries like `_gi` are built for a specific version. Plus there are a few breaking changes, yeah (ref: [3.9](https://docs.python.org/3/whatsnew/3.9.html#porting-to-python-3-9), [3.10](https://docs.python.org/3/whatsnew/3.10.html#porting-to-python-3-10)).
Dion avatar
cn flag
Interesting, thanks for the info!
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.