17

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
11
  • 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 ;-)
    – Rinzwind
    Oct 18 at 8:39
  • So python3.8 and python3.9 can be removed without breaking my Ubuntu install, right ? Oct 18 at 8:44
  • 2
    Thank you, I edited my post. Hope it is better now Oct 18 at 9:14
  • Yes, that's much better. Also add the output of ls -l /usr/bin/python[23]* /usr/local/bin/python[23]*, please.
    – muru
    Oct 18 at 9:18
  • Ok, please see my edit Oct 18 at 9:25
14

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.

3
  • 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, Oct 18 at 10:26
  • 1
    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 :-) )
    – Rinzwind
    Oct 18 at 10:35
  • 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.
    – wjandrea
    Oct 20 at 17:23
13

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).

13

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
4
  • 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.
    – wjandrea
    Oct 20 at 17:35
  • @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.
    – Dion
    Oct 20 at 21:48
  • 1
    If you change the symlink, things will break, like Gnome Terminal for example. 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, 3.10).
    – wjandrea
    Oct 20 at 23:03
  • Interesting, thanks for the info!
    – Dion
    Oct 21 at 19:24

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.