6

I can observe both versions of Python2 and Python3 in my Raspberry Pi.

Both of them were by default.

Why do we have both the version of python in Raspbian?

Is it safe to uninstall Python2 and only keep Python3?

4 Answers 4

13

Is it safe to uninstall Python2 and only keep Python3?

To be "safe" as in "don't break anything"? Probably not. But Python2 doesn't occupy much space - about 3MB on your SD card. And if you don't use it, it doesn't consume any resources.

It can be annoying to have python2 as the default, but you can cure that annoyance without removing it:

This is a job for update-alternatives :

Verify your system's baseline (this is from my system):

$ python --version
Python 2.7.16
$ python3 --version
Python 3.7.3

To make python use python3:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

The response should be:

update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode

Check baseline again:

$ python --version
Python 3.7.3
$ python3 --version
Python 3.7.3

See man update-alternatives for details. If you want to "undo" this:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

Which should yield this response:

update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode

4

Type sudo apt -s remove python2 and check out the list of packages which would have to be removed. You'll most likely see that half of your system will be gone if you do remove it.

2

You are likely to break things, but it would require significant effort to determine.

Why do you WANT to delete it, it uses little space and there are lots of other programs you don't use - do you plan to delete these too?

1

You could also install the package python-is-python3, which symlinks /usr/bin/python to python3.

sudo apt install python-is-python3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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